刷新页面会破坏 PHP 会话吗? [英] Does refreshing a page destroy PHP sessions?
问题描述
我有一个验证码命令,用于设置会话的值,然后在验证码不正确时刷新页面.
I've got a captcha command that sets the value of a Session and then refreshes the page if the captcha code isn't correct.
在页面的验证部分:
$_SESSION['refresh']=1;
echo '<META HTTP-EQUIV="Refresh" Content="0"; URL="contact-test.php">';
当页面加载时,它会运行一些 php 脚本,以查看是否为会话变量设置了值,如果有,则为警报框回显 javascript 函数,该函数通过在正文中调用onLoad 命令.
When the page loads it runs a bit of php script to see if there is a value set for a session variable, if there is it then echos a javascript function for an alert box, which called in the in the body via an onLoad command.
在代码的最开始:
session_start();
if (isset($_SESSION['refresh'])) {
echo '<script type="text/javascript">
function loadalert ()
{alert("Incorrect security code, please try again.")}
</script>';}
据我所知,当页面刷新会话值丢失时,我怀疑 session_start() 命令正在清除所有以前的会话.我尝试了一个测试回声,在循环之前和循环中发送一些文本和会话的值;只有循环之前的一个在刷新时没有会话值的情况下得到回显.
Near as I can tell when the page refreshes the sessions value is lost, I suspect the session_start() command is clearing all previous sessions. I've tried a test echo sending out some text and the value of the session, both before the loop and in the loop; only the one before the loop gets echoed without a session value at refresh.
推荐答案
否 只有在调用 session_destroy() 函数或设置到期日期时才会销毁会话.
No the session is only destroyed when you call the session_destroy() function or whenever the expiry date is set.
您还可以清空 SESSION 数组以销毁"SESSION 中的任何内容.
You can also empty the SESSION array to "destroy" whatever is inside the SESSION.
这篇关于刷新页面会破坏 PHP 会话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!