I have been searching for hours and cant find the answer to this one.
I am trying to add the referring url to an email message (form sent by visitor on the website) so I can know what website the visitor was referred from. (part of ongoing analytic).
I am trying to set the SERVER["HTTP_REFERER"] into a session like so..
if(!isset($_SESSION["inbound"])) {
$_SESSION["inbound"] = $_SERVER["HTTP_REFERER"];
}
but the session keeps changing every time another page is loaded. I presumed putting the ! before isset would tell it that there is already a session and not to try adding it again.
I have also tried it this way (and a combinations of other ways):
if(isset($_SESSION["inbound"])) {
// do nothing
} else {
$_SESSION["inbound"] = $_SERVER["HTTP_REFERER"];
}
I am doing this in WordPress, but I dont think that should be an issue. I have used sessions in Wordpress many times before without any problems.
Any advice or help is greatly appreciated! Thanks Eoin
UPDATE: Have tried it like this:
function get_ref_session() {
if(!isset($_SESSION["inbound"])) {
$the_referer = $_SERVER["HTTP_REFERER"];
$_SESSION["inbound"] = $the_referer;
}
}
add_action( 'wp_head', 'get_ref_session' );
No joy this way either :(
Tried this in the plugin and in functions.php, no joy. (at the top)
function register_session(){
if( !session_id() )
session_start();
}
add_action('init','register_session');