Why is my title ("Location: $ _SERVER ['HTTP_REFERER']"); PHP function not working?

It works when I enter

header("Location: http://www.google.com");

but it doesn’t work when I have

header("Location: $_SERVER['HTTP_REFERER']");

I want to redirect the page to any page from which it appeared.

+5
source share
6 answers

Try it: :)

if (!empty($_SERVER['HTTP_REFERER']))
    header("Location: ".$_SERVER['HTTP_REFERER']);
else
   echo "No referrer.";

However, to determine which page the user came from, I would prefer to use a session variable that gets reset on each page:

session_start();
echo "Previous page:", $_SESSION['loc'];
$_SESSION['loc']=$_SERVER['PHP_SELF'];

ps: This only works for local pages, you cannot track other websites.

+5
source

You can try:

header("Location: {$_SERVER['HTTP_REFERER']}");

, .

$_SERVER['HTTP_REFERER'], . , , , .

+4

. , $_server ['http_referer'], , , , - :

if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != ""){
$url = $_SERVER['HTTP_REFERER'];
}else{
$url = "YOUR INDEX PAGE OR SOMETHING";
}

header("Location: ".$url);
+3

, ( ).

, . , , ( - ).

+2
header("Location: $_SERVER[HTTP_REFERER]");

. .

+1

if(isset($_SERVER['HTTP_REFERER'])){
    header("Location:".$_SERVER['HTTP_REFERER']."");
}
0

All Articles