donglu8779 2013-04-28 17:17
浏览 39
已采纳

逻辑运算符(&&)在php中无法在本地工作

I'm still a beginner of php and I have come across a bit of a problem with the logical operator &&. I have a token and secret answer script which are both text boxes. When a user submits the token and there answer , the script goes into the database and if all checks clear (error messages etc), then goes through to the next step (Typing in there new password). The actual script works fine in my live site but for some reason its not working locally on my computer (which has got me a bit paranoid to be honest, just in case it's not 100% safe). With a lot of testing the script points to this bit of code :

if(isset($uid) && isset($uidTwo)) {
           header('Location: reset.php');
           exit();
       }

The $uid stores the users_id from the users database and the $uidTwo stores the tables_id from the answer database (which also has user_id as one of its primary columns). When both are matched (True), the script goes on to the reset page.

I have done a lot of tests, changing the && to || seems to work and processes it through to the next page but that way only works for the token box and you can type in anything in the answer box like (ftgyhh) for example, so that's no good.

I have checked for headers already sent etc because I have error messages but nothing seems to work for the script locally.

So does anybody have any ideas that I could of missed?

EDIT: Did a var_dump on $uidTwo and found it was NULL, then i realised it could be the database side, so i imported an earlier version of the database and found it was that. The script now works locally, but reading both the database sql files before and after, i can't see what i did wrong. Oh well, these things are there to try us. Cheers guys for all your help

  • 写回答

2条回答 默认 最新

  • dtgr3392 2013-04-28 17:26
    关注

    There is not enough information here to answer. FYI, you can do:

    if (isset($uid, $uidTwo)) {
        header('Location: reset.php');
        exit();
    }
    

    instead of using the &&.

    I would do something like

    echo $uid ? "Uid is set" : "Uid is not set";
    echo  $uidTwo ? "Uid2 is set" : "Uid2 is not set";
    

    before the header and start working my way back until they are not what I think they should be.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver