dongxin2734 2014-02-14 03:59
浏览 66

PHP会话变量不接受重新分配

I'm working on an registration system in PHP and am running into an issue. The users are inserted into the database as intended. Next, a token (just a hash of a random value) is attached to a url along with the user id, and this url is emailed to the user's email so they can verify it.

For example user 128 has this verification URL: localhost/fPASS/?page=verify_email&id=128&token=4a629a13871cf6d354984abdfd990783

Note the user id in the url is correctly noted as 128. If I visit the link, the script correctly compares the id and token with the database and changes email_verified to 1.

The problem is that if I try to register another user, the url is regenerated with the id and token for user 128 instead of 129... Unless I clear my cookies. Now the url uses session variables to determine the id and token, so it seems they aren't updating properly. The registration function, however, always reassigns the variables if there are no errors (which there aren't):

// if there are no errors, redirect to success page
if (!isset($errors))
{
    // send the email address on to the next page in case the verification email needs to be re-sent
    $_SESSION['email'] = $safe['email'];
    $_SESSION['account_id'] = $account_id;
    $_SESSION['token'] = $token;
    header('Location: http://localhost/fPASS/?page=reg_success');
}

The reassignments don't seem to be taking effect though. What could cause the original assignments to get "stuck" in the session variables?

  • 写回答

2条回答 默认 最新

  • dtjzpg5313 2014-02-14 08:51
    关注

    Please check if you've included session_start(); in your php. Then, try echo your session variables or the assignment variables *before redirecting it*. This will help you in debugging easily.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度