PHP 保存会话变量
我正在尝试来自此处的新验证码脚本。要调用您使用的验证码: $_SESSION['captcha']['code']
好吧,当我在主表单上回显它时,但是当我在表单被删除后回显它时,它会起作用。提交后,它会显示一个新代码,因此我永远无法找出他们提交表单时的旧代码是什么。
if($_POST['submit']) {
echo $_SESSION['captcha']['code'];
}
我怎样才能保存会话数据并且不再改变它?
I am trying a new CAPTCHA Script from here. To call the CAPTCHA code you use: $_SESSION['captcha']['code']
Well that works when I echo it out on the main form, but when I echo it after the form has been submitted, it displays a new code so I can never find out what the old code was when they submitted the form.
if($_POST['submit']) {
echo $_SESSION['captcha']['code'];
}
How can I save that session data and not make it change any more?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该将其存储在您自己的 SESSION 变量中:
然后,当提交表单时,使用您自己的变量:
You should store it in your own SESSION variable:
Then, when the form is submitted, use you own variable:
将其放在下一步中再次包含 captcha.php 之前。
Put that BEFORE you include the captcha.php again on the next step.
我的猜测是,它会显示一个新代码,因为您返回到显示它的页面。尝试提交到不同的页面,或者如果会话变量已设置,则可能不执行验证码创建代码。
My guess is that it displays a new code because you come back to the page that displays it. Try submitting to a different page, or maybe not executing the captcha creation code if the session variable is already set.