Check for a number

Hello, I have this check:

if ($_SERVER["HTTP_REFERER"] != "http://site.loc/catalog.php?id=27") {
echo ""; }

How to make such a check, but instead of the number 27, put some template that checks if the number is true?


Answer 1, authority 100%

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 remove line 3

UPD: maybe you need this Re:

if ( preg_match("/^http\:\/\/site\.loc\/catalog\.php\?id=(\d+)(?:$|&)/", $ref) ){

Answer 2

$url = "http://site.loc/catalog.php?id=27";
if(preg_match("#id=(\d)#ui", $url) && $_SERVER["HTTP_REFERER"] != $url)
{
    echo "";
}

Something like that.


Answer 3

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