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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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
> [EMAIL PROTECTED]
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to