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 Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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} Quote Link to comment 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 Quote Link to comment 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.