Home > Backend Development > PHP Tutorial > 关于后退后提交数据,COOKIE会延迟一步,求解决方案。

关于后退后提交数据,COOKIE会延迟一步,求解决方案。

WBOY
Release: 2016-06-23 14:03:36
Original
1090 people have browsed it

a.php

<form action="b.php" method="GET" onsubmit="return check(this)"><input type="checkbox" name="L1agy" value="1"  />是<input type="button" name="Submit" value="上一步" onclick="javascript:window.history.back();"/> <input type="submit" value="下一步" /></form>
Copy after login


b.php
<?php		if(empty($_GET['L1agy'])){			setcookie("DATA_L1agy","0", time()+3600*24);			}else{			setcookie("DATA_L1agy","1", time()+3600*24);		}		echo $_COOKIE['DATA_L1agy'];?>
Copy after login


当在a.php勾选是,然后点击下一步,将数据提交给b.php,显示“1”。
这时候点击上一步,返回将是的勾选去掉,然后再点下一步,还是会显示“1”。
再点上一步,然后再点下一步,这是才会显示“0”。

这种不同步产生的原因是什么?求解决方案。


回复讨论(解决方案)

第一次提交没有值吧。你的能显示1 ?
setcookie 之后要下次加载时才可见cookie. 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template