Hello, I have such a check here:
if ($_SERVER["HTTP_REFERER"] != "http://site.loc/catalog.php?id=27") { echo "текст"; }
How to make such a check, just replace the number 27, put some template that checks if the number is true
?
Hello, I have such a check here:
if ($_SERVER["HTTP_REFERER"] != "http://site.loc/catalog.php?id=27") { echo "текст"; }
How to make such a check, just replace the number 27, put some template that checks if the number is true
?
You can do this:
<? //$ref = $_SERVER["HTTP_REFERER"]; $ref = "http://site.loc/catalog.php?id=27"; if( preg_match("/(?:\?|&)id=(\d+)(?:$|&)/", $ref) ){ echo "OK"; } ?>
To use remove //
from line 2 and delete line 3
UPD: maybe you need this Re:
if ( preg_match("/^http\:\/\/site\.loc\/catalog\.php\?id=(\d+)(?:$|&)/", $ref) ){
$_SERVER["HTTP_REFERER"]
- this is where the person came from (almost the same as the previous page) <br> You may need to use $_SERVER['QUERY_STRING']
- this is the current address line data <br> - timka_s $url = "http://site.loc/catalog.php?id=27"; if(preg_match("#id=(\d)#ui", $url) && $_SERVER["HTTP_REFERER"] != $url) { echo "текст"; }
Something like this.
(\d)
Replace with 27. Or read about strpos. - ling if(empty($_GET)) { echo 'Empty GET'; } else { if(is_numeric($_GET['id'])) { echo $_GET['id']; // Good is true // Put a template } else { echo 'Numeric is empty'; } }
http: //site.loc/catalog.php -> result Empty GET
http: //site.loc/catalog.php? id = 27 -> result Good is true
http: //site.loc/catalog.php? id = bb -> result Numeric is empty
Source: https://ru.stackoverflow.com/questions/49561/
All Articles