PHP $SERVER['HTTP_REFERER'] doesn't exist

Account nane

epiz_28268815

Error Message

$SERVER[‘HTTP_REFERER’] doesn’t exist

Other Information

I tried to access the superglobal variable $SERVER[‘HTTP_REFERER’], but it doesn’t seem to exist. In fact, by doing a var_dump of $SERVER, there is no key named HTTP_REFERER (which detects the page from which you are being redirected). How do I access this value

Correct usage:

$_SERVER["HTTP_REFERER"]

You forgot the “_”.

4 Likes

Sorry, I forgot to write the “_” here in the question, but I wrote it in my code

In that case, could you please share your code?

1 Like

Sharing what you think is the code is not going to help us. Please copy and paste the actual code from your application here.
Thanks

3 Likes

This is the code that doesn’t work (it works only on localhost, but not on infinityfree host):

<?php
session_start();

if (str_contains($_SERVER['HTTP_REFERER'], 'some_text') || str_contains($_SERVER['HTTP_REFERER'], 'some_text')) {
   echo "<a href=\"some_page.php\" class=\"go-back\" ><i class=\"fas fa-arrow-left\"></i>Some text</a>";
} 

if (str_contains($_SERVER['HTTP_REFERER'], 'some_text')) {
        echo "<a href=\"some_page\" class=\"go-back\"><i class=\"fas fa-arrow-left\"></i>Some text</a>";
}
?>

The problem is that $_SERVER[‘HTTP_REFERER’] doesn’t exist in $_SERVER.
Why?

In w3schools.com it says, “Returns the complete URL of the current page (not reliable because not all user-agents support it)”, might be that.

2 Likes

Do you know any other way to see which page you are being redirected from, accepted on infinityfree

Maybe $_SERVER[“REQUEST_URI”] or $_SERVER[“PHP_SELF”] in a session variable.

Ok thanks

is the name of an optional HTTP…

optional

Since referer is optional, it must not be included in the request. That is most likely why you are not seeing it.

Also, fun fact: “referer” is misspelled and should be referer. If your inner English gets the better of you and writes “referrer”, while it is grammatically correct, the syntactically correct name is “referer”.

4 Likes

If you control the page redirecting itself, you can use POST or GET by sending the current URL to the page you are redirecting to.

Otherwise, if the page redirecting itself to you doesn’t provide information on itself, you will never know.

Privacy is a thing ya know
1 Like

Thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.