Am使用以下代码重定向url字符串是否与代码抛出的方式匹配"警告:使用未定义的常量";错误还有,如果字符串是区分大小写的,代码也不起作用,请帮助我解决这个问题(php 7.2版(
<?php
if(isset($_GET['Keyword'])){
if($_GET['Keyword'] == Test){
header('Location: http://www.anotherURL.com');
exit ();
}
}
?>
实际上您的错误显示
警告:使用未定义的常量
表示上述代码中第3行使用的测试未定义
要么像这个一样定义测试
<?php
define("TEST", "key words to match", true); //here true is used for case-insensitive
if(isset($_GET['Keyword'])){
if($_GET['Keyword'] == Test){
header('Location: http://www.anotherURL.com');
exit ();
}
}
?>
或将其用作字符串
<?php
if(isset($_GET['Keyword'])){
if($_GET['Keyword'] == "Test"){ //qoutes " are necessary for string
header('Location: http://www.anotherURL.com');
exit ();
}
}
?>