Re: Using Cookies

From: Date: Sun, 11 Mar 2001 01:47:15 +0000
Subject: Re: Using Cookies
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43355@lists.php.net to get a copy of this message
It seemed I thought it should work at least. But it does not on PHP4.0.4pl1. Try following code <?php $user = empty($HTTP_GET_VARS['user']) ? '' : $HTTP_GET_VARS['user']; $pw = empty($HTTP_GET_VARS['pw']) ? '' : $HTTP_GET_VARS['pw']; $cookieuser = empty($HTTP_COOKIE_VARS['user']) ? '' : $HTTP_COOKIE_VARS['user']; if (!$cookieuser) { setcookie('user', $user, time() + 864000); print('Setting a cookie<br>'); } print('The user is ' . $user . '<br>'); print('The password is ' . $pw . '<br>'); if (empty($cookieuser)) { print('No cookie was set...will set one<br>'); } else { print('Cookie user name: ' . $cookieuser . '<br>'); } echo('<pre>'."\n"); print_r($HTTP_COOKIE_VARS); echo('</pre>'."\n"); ?> FYI: You better to set error reporting to E_ALL. You didn't enclose array index. E_ALL will be very helpful to find type AND to write better code. I don't recommend to use short tag. Use <?php instead. Regards, -- Yasuo Ohgaki ----- Original Message ----- From: "Todd Cary" <todd@aristesoftware.com> To: <php-general@lists.php.net> Sent: Sunday, March 11, 2001 1:59 AM Subject: [PHP] Using Cookies > This is a test script so I can get an understanding of Cookies. What am > I missing with this? $cookieuser never gets a value. > > <? > $user = $HTTP_GET_VARS[user]; > $pw = $HTTP_GET_VARS[pw]; > $cookieuser = $HTTP_COOKIE_VARS[user]; > if (!$cookieuser) { > setcookie("user", $user, time() + 864000); > print("Setting a cookie<br>"); > } > > print("The user is " . $user . "<br>"); > print("The password is " . $pw . "<br>"); > if (empty($cookieuser)) { > print("No cookie was set...will set one<br>"); > } else { > print("Cookie user name: " . $cookieuser . "<br>"); > } > ?> > > > > -- > Todd Cary > Ariste Software > todd@aristesoftware.com > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#43355) next »