Issue
Am using the below code to redirect if the url string matches how ever the code is throwing "Warning: Use of undefined constant" error also the code does not work if the String is Case Sensitive, Please help me solve this issue (php version 7.2)
<?php
if(isset($_GET['Keyword'])){
if($_GET['Keyword'] == Test){
header('Location: http://www.anotherURL.com');
exit ();
}
}
?>
Solution
actually your error says
Warning: Use of undefined constant
means Test used on line 3 in code mentioned is not defined
either define Test like this
<?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 ();
}
}
?>
or use it as a string
<?php
if(isset($_GET['Keyword'])){
if($_GET['Keyword'] == "Test"){ //qoutes " are necessary for string
header('Location: http://www.anotherURL.com');
exit ();
}
}
?>
Answered By - Ahmed Raza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.