开发者

PHP Saving Session Variable

I am trying a new CA开发者_StackOverflow社区PTCHA 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?


You should store it in your own SESSION variable:

$_SESSION['old_captcha'] = $_SESSION['captcha'];

Then, when the form is submitted, use you own variable:

if($_POST['submit']) {
    echo $_SESSION['old_captcha']['code'];
}


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜