npsari Posted November 12, 2007 Share Posted November 12, 2007 Hi there, I set up a php page which has this little code <?php setcookie("try", "Me Try", time()+3600); ?> then, when i try to read it from any other directory, i cant <? echo "Welcome " . $_COOKIE["try"] . "!"; ?> I only can read it if i upload the script in the same directory where the cookie was set How can i make a cookie, where all pages can read it, is that possible Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/ Share on other sites More sharing options...
Branden Wagner Posted November 12, 2007 Share Posted November 12, 2007 first.. read a little on http://us.php.net/manual/en/function.setcookie.php second change setcookie("try", "Me Try", time()+3600); TO setcookie("try", "Me Try", time()+3600, "/", YOURDOMAIN); [code] [/code] Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/#findComment-390215 Share on other sites More sharing options...
npsari Posted November 12, 2007 Author Share Posted November 12, 2007 I was reading, and did not manage to find this little info yet so, it should be like that? setcookie("try", "Me Try", time()+3600, "/", http://www.example.com); cus iam getting erros Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/#findComment-390217 Share on other sites More sharing options...
Branden Wagner Posted November 12, 2007 Share Posted November 12, 2007 it should be just example.com not http://www.example.com Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/#findComment-390219 Share on other sites More sharing options...
npsari Posted November 12, 2007 Author Share Posted November 12, 2007 ohh, nice, i try it now Just a little extra question setcookie("try", "Me Try", time()+3600, "example.com"); the above cookie expires in 1 day i think what if i want to make it 1 week Can you tell me what to use Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/#findComment-390223 Share on other sites More sharing options...
Branden Wagner Posted November 12, 2007 Share Posted November 12, 2007 obviously you didnt read: http://us.php.net/manual/en/function.setcookie.php 3600 is 1 hour in seconds... so your answer is time()+ {1 week in seconds} Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/#findComment-390229 Share on other sites More sharing options...
npsari Posted November 12, 2007 Author Share Posted November 12, 2007 I read it actually, cant deny i didnt understand much, but thanks for the help it works now Link to comment https://forums.phpfreaks.com/topic/77053-solved-a-little-cookie-problem/#findComment-390237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.