Jump to content

Archived

This topic is now archived and is closed to further replies.

jparker

Cookie problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
Dont use HTTP_*_VARS variables use the new superglobal arrays (_POST, _GET, _COOKIES, _SESSION, etc). So use the following:
[code]<?php

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

?>[/code]

Share this post


Link to post
Share on other sites
Thanks very much it has worked now.

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

James

Share this post


Link to post
Share on other sites
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 [b]register_long_arrays[/b] on in the php.ini. But they are becoming depreciated, hense why they are going to be removed as of PHP6 I believe.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.