I have this php script in my header.php file, sending HTTP headers to a python script, and setting a GUID as a session cookie:
<?php
ob_start();
function guid(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
$UA = $_SERVER['HTTP_USER_AGENT'];
$REF = $_SERVER['HTTP_REFERER'];
$IP = $_SERVER['REMOTE_ADDR'];
$GUID = guid();
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (!isset($_COOKIE["name"]))
setcookie('name',$GUID);
//echo $UA;
//echo $REF;
//echo $IP;
//echo $GUID;
echo exec("python /var/www/html/oscommerce-2.3.3.4/header_sender.py -u '$UA' -r '$REF' -i '$IP' -c '$GUID' -p '$actual_link' 2>&1");
ob_end_flush();
?>
The problem I'm seeing is that this generates a new GUID for every page load in the same session - the session cookie seems to be not stored.
What could the problem be? Thanks
Seems like you don't declare session_start()
;
EDIT :
Since you're not using $_SESSION[" "]
but instead $_COOKIE[" "]
.
It seems like you don't define how long the cookie will be stored on your browser by time() + x seconds
setcookie('name',$value,time()+..);