Jump to content


Photo

Cookie problem


  • Please log in to reply
3 replies to this topic

#1 jparker

jparker
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 May 2006 - 08:09 AM

Hello

I have 2 very simple scripts that sets and then gets a cookie to test to see all is working

The set script below seems to run without problems : -

<?php
setcookie ("user", "jparker", time()+604800);
?>

the get script below however doesn't work and creates an error in the apache log

<?php
$user = $HTTP_COOKIE_VARS["user"];
echo "Hello ".$user;

?>

The error is : -

[client 127.0.0.1] PHP Notice: Undefined variable: HTTP_COOKIE_VARS get.php on line 2

Could you possible point me in the right direction on how to solve this. I'm guessing its a PHP/Apache configuration issue

Thanks

James



#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 May 2006 - 08:12 AM

Dont use HTTP_*_VARS variables use the new superglobal arrays (_POST, _GET, _COOKIES, _SESSION, etc). So use the following:
<?php

$user = $_COOKIE['user'];
echo "Hello " . $user;

?>


#3 jparker

jparker
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 May 2006 - 08:35 AM

Thanks very much it has worked now.

Having seen $HTTP_COOKIE_VARS in examples for retrieving cookies is this now obsolete?

James

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 May 2006 - 04:14 PM

Yes the old $HTTP_*_VARS variables will not exist as of PHP6 and they are also disabled by defualt as of PHP4.1.0. You can still use them by turning register_long_arrays on in the php.ini. But they are becoming depreciated, hense why they are going to be removed as of PHP6 I believe.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users