hi rodney, here are the snippets of code that i used to create the cookie. 🙂 i hope the cookie can grab the timestamp when i first loads the page. this is because i would like to insert the time & page accessed into a table to log users' activity on the site.
i assume that this delivery.php page will be refreshed many times because i have a search function that loads in the same page & also when user sorts the records by clicking on my header, the information is passed and the page is reloaded again.
//some parts of the code in delivery.php
$prevpage=substr($HTTP_REFERER, 37);
$prevpage2=explode('?',$prevpage);//to get rid parameter passed in thru URL because i pass the sorting parameter.
$prevpage=$prevpage2[0];
$ntime=mktime();
//when page is 1st loaded, set the cookie time
if ($prevpage!="delivery.php"){
if (!isset($_COOKIE['cookie_time'])) {
setcookie("cookie_time", $ntime, time() + 3600);
}
$_COOKIE['cookie_time'] = $ntime;
echo "<br>Cookie time:".$_COOKIE['cookie_time']; //this is displayed when page is loaded for the 1st time
}
//get cookie time if page is reloaded again
if (isset($_COOKIE['cookie_time'])) {
echo "<br>Always Cookie Time:".$_COOKIE['cookie_time'];//this is displayed when page is loaded for the 1st time but NOT when the page refreshes
}
else {
echo "Why not set?!!"; //displayed everytime when i perform sorting & the page reloads again
}
}
sorry for not posting all the code because the rest are just values that echo out from database or html coding. just would like to focus on setting my cookie right first before proceeding. sigh! thank you very much rodney!