开发者

Why isnt php reading my cookie?

at index.php i have a form to fill out some settings. the form posts to setsettings.php

at setsettings.php it uses the form data and sets some cookies and redirect back to index.php. if i print_r($_COOKIE) at setsettings.php all is wel开发者_如何学Cl. but nothing comes up at index.php, the $_COOKIE array is empty :(

Does somebody know how i go about solving this?

I set det setting by (setsettings.php):

/* Write new cookie */
$expire = 60 * 60 * 24 * 60 + time();  // ~2 months
setcookie("user_var_001", $_POST['selection'], $expire);

and in index.php print_r($_COOKIE) turns up blank;


Copy-paste from PHP: setcookie comments:

When setting a cookie on a page that redirects, the cookie must be set after the call to header('Location: ....');

Such as:

<?php 
header('Location: http://www.example.com/'); 
setcookie('asite', $site, time()+60*60, '/', 'site.com'); 
?>

I suggest searching that page for "redirect", there is also some problem described about IIS.

P.S. Try without the redirect and see if the cookie is set after you refresh the page.


setcookie() function is called before any code was printed?


Try printing $_COOKIE['user_var_001']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜