开发者

Display the cookies values in the same page php-cookies

开发者 https://www.devze.com 2023-02-03 20:05 出处:网络
I have开发者_Go百科 text box and submit button. I write something in the text box and set a cookies for the text box values on sumbit.

I have开发者_Go百科 text box and submit button. I write something in the text box and set a cookies for the text box values on sumbit. And put the form action to the same page and display the cookies information. The problem is that without refreshing the page,the cookies values is not being displayed or before refreshing,it display the previous cookies value.


<?php
 header('Cache-Control: no-store, no-cache, must-revalidate');
 header('Cache-Control: post-check=0, pre-check=0', FALSE);
 header('Pragma: no-cache');
?>

taken from Sitepoint, this is just an option. Can you post code...


After setting cookie you have to redirect on the same page.

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE

so you have to make a redirection on same page.

<?php
if (isset($_POST['submit']))
{
    setcookie("TestCookie", 'shakti', time()+3600);  /* expire in 1 hour */
    header('location:test.php');die();
}
?>
<form action="" method="post">
<input type="submit" name="submit">
</form>
<?php 
print_r($_COOKIE);
?>
0

精彩评论

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