Forum Moderators: coopster
Need to knows;
1.where to put the code snippet i.e. before all outputs?
2.how to check if it exists already and not to set it again.
3.how to set it to something unique like i was going to use.
$dt = date();
$ra = $REMOTE_ADDR;
$UID = "$dt$ra";
setcookie("UID", "$UID", time()+60*60*24*30);
4.can i add this code at the top of an html page within <?php?>
1. Cookies should go together with the headers, so it has to precede the output contents.
2. To check whether a cookie exists, apply the traditional isset function..
if(isset($_COOKIE['cookie_name'])){
// do whatever
}
3. If what u want to know is whether u can use "UID" as the cookie name the answer is yes, you can. and u've got it right there. just make sure u use the proper variables and concatenate the strings right.
4. you can add it to any page you like.. but remember, only php pages (.php, .php3, .phtml etc) would actually execute the code.