0

I am using the below to get the referring URL but what I would like to check is whether $ref has a variable in it.

Referring Link http://domain.com/?s=checking

Current Link http://domain.com/product/cheese

Ideally I would like to be able to use PHP to check if the variable $ref has the GET Variable s in it

PHP

$ref = $_SERVER['HTTP_REFERER'];
3
  • 1
    Why not just isset($_GET['s']) ? Commented Mar 19, 2014 at 11:20
  • @Rikesh does that work when you are getting the Referring URL? The variable s won't be in the current page URL Commented Mar 19, 2014 at 11:21
  • Yes, HTTP_REFERER will show you the exact URL Commented Mar 19, 2014 at 11:22

1 Answer 1

3
$queryParams = parse_url($ref, PHP_URL_QUERY);
if ($queryParams) {
    parse_str($queryParams, $values);
    if (isset($values['s'])) { 
        echo 'Has query param s: ', $values['s'];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.