You inverted the variable and the value in your 2nd page
<?php
session_start();
$variable1 = $_SESSION['ref'];
echo $variable1;
Pergunta
So I'm currently trying to save page1.php's HTTP_REFFERER
as a variable and transfer that variable to another page. I've tried using $_SESSION[]
and $_COOKIES[]
methods but it didn't work. page2.php
shows referrer as page.php
.
Any suggestions?
page1.php :
<?php session_start();
$variable1 = $_SERVER['HTTP_REFERER'];
$_SESSION['ref'] = $variable1;
page2.php :
<?php session_start();
$_SESSION['ref'] = $variable1;
echo $variable1; ?>
Solução
You inverted the variable and the value in your 2nd page
<?php
session_start();
$variable1 = $_SESSION['ref'];
echo $variable1;
Outras dicas
$_SERVER['HTTP_REFERER'] is a predefined env variable. To access stored variable use for example $_SESSION['HTTP_REFERER'] on page2.php
In page1.php, make sure to end the code correctly:
<?php session_start();
$variable1 = $_SERVER['HTTP_REFERER'];
$_SESSION['ref'] = $variable1;
?>
In page2.php just print_r
the $_SESSION['ref']
or assign it to a variable and then use echo
.
Also the order of the variables is incorrect, should be:
$variable1 = $_SESSION['ref'];
HTH.