dhimok Posted June 25, 2007 Share Posted June 25, 2007 Hi How can I set a cookie the first time page loads? thanks Quote Link to comment https://forums.phpfreaks.com/topic/57027-setting-a-cookie-on-page-load/ Share on other sites More sharing options...
TheFilmGod Posted June 25, 2007 Share Posted June 25, 2007 setcookie("usr", "Ellie Quigley"); setcookie("color", "blue"); realize that the server has a limit of 20 cookies per user. A cookie can store only one piece of info at a time. So if you want to store multiple items use multiple cookies or use arrays. I hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/57027-setting-a-cookie-on-page-load/#findComment-281697 Share on other sites More sharing options...
dhimok Posted June 25, 2007 Author Share Posted June 25, 2007 I am trying to set this cookie if(!isset($_COOKIE["uid"])) { $uid = session_id().@time(); $expire = 50*365*24*60*60; // almost 50 years setcookie("uid", $uid, time() + $expire); when I first load the page this cookie is not set. on page reload or by clicking on a link, i mean second try then it sets the cookie. Why isnt set on first try and how can I do that Quote Link to comment https://forums.phpfreaks.com/topic/57027-setting-a-cookie-on-page-load/#findComment-281706 Share on other sites More sharing options...
sKunKbad Posted June 25, 2007 Share Posted June 25, 2007 This will work: <?php session_name("uid"); session_set_cookie_params(50*365*24*60*60); session_start(); ?> Nobody will have their current computer in 50 years, so making a cookie that lasts that long is pointless. Quote Link to comment https://forums.phpfreaks.com/topic/57027-setting-a-cookie-on-page-load/#findComment-281750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.