How to check what the referer url query is?

46 Views Asked by At

lets say I have this $_SERVER["HTTP_REFERER"] output https://example.com/index.php?queryexample=myquery

I want to check if the url query is "queryexample=myquery" and if it's not then the code should say something like "the query is not queryexample=myquery".

I'm aware that I can get the query with ...

$URL = $_SERVER["HTTP_REFERER"];
$query = basename(parse_url($URL, PHP_URL_QUERY));
if(isset($query)) {
echo $query;
}

But I want an output only if the query is "queryexample=myquery".

Thanks in advance!

1

There are 1 best solutions below

2
Schlotter On

This may help, to solve your problem: Check if the array key queryexample exists in $_GET since the query could include more then your queryexample:

<?php
if(array_key_exists('queryexample', $_GET)) {
    if($_GET['queryexample'] === 'myquery') {
        echo 'good';
    }
}
?>