On Mon, Mar 4, 2013 at 5:58 PM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx> wrote: > On Tue, 2013-03-05 at 10:19 +1030, David Robley wrote: > >> Angela Barone wrote: >> >> > On Mar 4, 2013, at 11:33 AM, Ashley Sheridan wrote: >> >> You can manually write a cookie on your machine, or use a special script >> >> that only you visit that contains a setcookie() call (it only need be set >> >> once). From there on, you can check the $_COOKIES super global for the >> >> presence of your cookie. >> > >> > I don't know why, but I can't get cookies to work. Here's a script I'm >> > calling from my browser: >> > >> > <?php >> > $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? >> > $_SERVER['HTTP_HOST'] : false; >> > $cookie = setcookie('test2', '123' , time()+60*60*24*30, '/', $domain); >> > ?> >> > >> > <!DOCTYPE html> >> > <html lang="en"> >> > <head> >> > <meta charset="utf-8" /> >> > <title>Test Page</title> >> > </head> >> > <body> >> > <?php echo 'Cookie is: '.$_COOKIE[$cookie]."<br>"; ?> >> > <?php echo 'Domain is: '.$domain."<br>"; ?> >> > </body> >> > </html> >> > >> > The domain is being displayed but the cookie is not. There's no cookie in >> > the browser prefs, either. What am I doing wrong? >> > >> > Angela >> >> Misunderstanding what $cookie contains? It is a boolean, i.e. it will be >> true or false depending on whether the cookie was set or not. To echo the >> contents of a cookie, you need to use the cookie name, viz >> >> <?php echo 'Cookie is: '.$_COOKIE['test2']."<br>"; ?> >> >> -- >> Cheers >> David Robley >> >> Oxymoron: Sisterly Love. >> >> > > > Not just that, but if you set a cookie, you won't be able to retrieve it > in the same script I believe. It's only available in the $_COOKIES array > once you refresh the page, as that's when the super global is populated > from the cookie data that the browser sends. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > Same script *invocation*. The cookie gets set when the response is sent back to the client. If the client calls the same script again, that cookie then uploaded. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php