!!!!! Posted May 17, 2007 Share Posted May 17, 2007 Okay... I am trying to make a cookie that goes all across my website so it can keep displaying the information, but I only know how to make the cookie availabe on the page it was made at. I really don't want my website viewers having to keep using the info in Forms... So, can anybody please tell me how to make a cookie work all across my website? Thanks Link to comment https://forums.phpfreaks.com/topic/51899-making-cookies-work-all-across-a-website/ Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 www.php.net/setcookie I would suggest reading that whole page thoroughly. Especially at the option domain and path parameters. Link to comment https://forums.phpfreaks.com/topic/51899-making-cookies-work-all-across-a-website/#findComment-255860 Share on other sites More sharing options...
realjumper Posted May 17, 2007 Share Posted May 17, 2007 The cookie has to be set in the root directory to be able to be accessed by all pages.....I found this out a while ago as the cookie was being set in the current directory, which meant that when another directory was being accessed, the cookie didn't work. Try this.... <? setcookie ("cookie", "Hello", 0, "/"); // The "/" sets the cookie to root directory ?> //If you echo out $_COOKIE["cookie"], it will display "Hello". Link to comment https://forums.phpfreaks.com/topic/51899-making-cookies-work-all-across-a-website/#findComment-255865 Share on other sites More sharing options...
!!!!! Posted May 17, 2007 Author Share Posted May 17, 2007 The cookie has to be set in the root directory to be able to be accessed by all pages.....I found this out a while ago as the cookie was being set in the current directory, which meant that when another directory was being accessed, the cookie didn't work. Try this.... <? setcookie ("cookie", "Hello", 0, "/"); // The "/" sets the cookie to root directory ?> //If you echo out $_COOKIE["cookie"], it will display "Hello". I pasted that code into a Notepad, then made another one and put this in it: <?php echo $_COOKIE["cookie"]; ?> And the webpage is blank. Any answers to why?? Link to comment https://forums.phpfreaks.com/topic/51899-making-cookies-work-all-across-a-website/#findComment-255889 Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 Are you working with Localhost? If so look here: http://www.aeonity.com/frost/php-setcookie-localhost-apache If not, try adding the domain parameter after the "/". IE: <?php // set cookie for one hour setcookie ("cookie", "Hello", time()+3600, "/", 'yourdomain.com'); Note there is a difference between www.yourdomain.com and yourdomain.com, use which ever you want but there is a difference. Link to comment https://forums.phpfreaks.com/topic/51899-making-cookies-work-all-across-a-website/#findComment-255892 Share on other sites More sharing options...
realjumper Posted May 17, 2007 Share Posted May 17, 2007 Have a look in your browser preferences to see if the cookie is being set ot not Link to comment https://forums.phpfreaks.com/topic/51899-making-cookies-work-all-across-a-website/#findComment-255898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.