1. <i id='imqYC'><tr id='imqYC'><dt id='imqYC'><q id='imqYC'><span id='imqYC'><b id='imqYC'><form id='imqYC'><ins id='imqYC'></ins><ul id='imqYC'></ul><sub id='imqYC'></sub></form><legend id='imqYC'></legend><bdo id='imqYC'><pre id='imqYC'><center id='imqYC'></center></pre></bdo></b><th id='imqYC'></th></span></q></dt></tr></i><div id='imqYC'><tfoot id='imqYC'></tfoot><dl id='imqYC'><fieldset id='imqYC'></fieldset></dl></div>
      <legend id='imqYC'><style id='imqYC'><dir id='imqYC'><q id='imqYC'></q></dir></style></legend>
      • <bdo id='imqYC'></bdo><ul id='imqYC'></ul>
      <tfoot id='imqYC'></tfoot>

      <small id='imqYC'></small><noframes id='imqYC'>

      1. 当 header(Location: xxx) 在里面时 PHP if 语句被忽略

        PHP if-statement ignored when header(Location: xxx) is inside(当 header(Location: xxx) 在里面时 PHP if 语句被忽略)
      2. <tfoot id='E53lM'></tfoot>
        <i id='E53lM'><tr id='E53lM'><dt id='E53lM'><q id='E53lM'><span id='E53lM'><b id='E53lM'><form id='E53lM'><ins id='E53lM'></ins><ul id='E53lM'></ul><sub id='E53lM'></sub></form><legend id='E53lM'></legend><bdo id='E53lM'><pre id='E53lM'><center id='E53lM'></center></pre></bdo></b><th id='E53lM'></th></span></q></dt></tr></i><div id='E53lM'><tfoot id='E53lM'></tfoot><dl id='E53lM'><fieldset id='E53lM'></fieldset></dl></div>
            • <bdo id='E53lM'></bdo><ul id='E53lM'></ul>
            • <legend id='E53lM'><style id='E53lM'><dir id='E53lM'><q id='E53lM'></q></dir></style></legend>

              1. <small id='E53lM'></small><noframes id='E53lM'>

                    <tbody id='E53lM'></tbody>
                  本文介绍了当 header(Location: xxx) 在里面时 PHP if 语句被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个奇怪的问题.我的页面顶部有一个 if 语句,当 header(location: xxx) 命令在其中时,它似乎被忽略了.

                  I have a strange problem. There is an if-statement at the top of my page that seems to be ignored when a header(location: xxx) commmand is inside of it.

                  $check = $authorisation->check(); 
                  // i know this results in true by echoing the value 
                  // (you've got to believe me on this one)
                  
                  if(!$check){
                      // redirect to message
                      header("Location: message.php");
                      exit;
                  
                  }else{
                      // do nothing, continue with page
                  }
                  

                  无论 $authorisation->check() 的结果如何,这总是重定向到 message.php 页面!

                  This ALWAYS redirects to the message.php page, no matter what the outcome of $authorisation->check() is!

                  奇怪的是,当我注释掉 header-command 并将 echo 放在 if 语句中进行验证时,一切都按预期工作:

                  Strange thing is, when I comment out the header-command, and put echo's in the if-statement for verification, all works as to be expected:

                      $check = $authorisation->check(); // true
                      if(!$check){
                          // redirect to message
                          echo "you are not welcome here";
                      }else{
                          echo "you may enter";
                      }
                  

                  结果是你可以进入";

                  这也可以按预期工作:

                      $check = true;
                      if(!$check){
                          // redirect to message
                          header("Location: message.php");
                          exit;
                  
                      }else{
                          // do nothing
                      }
                  

                  这只会在 $check = false 时重定向到消息页面;

                  This only redirects to the message page when $check = false;

                  最后一个有趣的事情是我只在一台服务器上遇到了这个问题,同样的脚本在 testserver 上运行完美.

                  Last funny thing is that I experience the problem only on 1 server, same script works flawlessly on testserver.

                  任何帮助将不胜感激!

                  推荐答案

                  你应该总是在完成 headers 之后运行 exit 以便浏览器的传输更快更稳定.

                  you should always run exit after you are finished with headers so that the transfer is faster and more stable for the browser.

                  试试这个方法:

                  if( ... )
                  {
                       header("Location: message.php");
                       exit;
                  }
                  
                  // ...
                  

                  请阅读评论以获取其他提示,了解为什么这是一个好主意.

                  Please read the comment for other tip's on why this is a good idea.

                  这篇关于当 header(Location: xxx) 在里面时 PHP if 语句被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <tbody id='LvqZN'></tbody>
                • <small id='LvqZN'></small><noframes id='LvqZN'>

                    <legend id='LvqZN'><style id='LvqZN'><dir id='LvqZN'><q id='LvqZN'></q></dir></style></legend>

                      <i id='LvqZN'><tr id='LvqZN'><dt id='LvqZN'><q id='LvqZN'><span id='LvqZN'><b id='LvqZN'><form id='LvqZN'><ins id='LvqZN'></ins><ul id='LvqZN'></ul><sub id='LvqZN'></sub></form><legend id='LvqZN'></legend><bdo id='LvqZN'><pre id='LvqZN'><center id='LvqZN'></center></pre></bdo></b><th id='LvqZN'></th></span></q></dt></tr></i><div id='LvqZN'><tfoot id='LvqZN'></tfoot><dl id='LvqZN'><fieldset id='LvqZN'></fieldset></dl></div>
                    1. <tfoot id='LvqZN'></tfoot>

                          <bdo id='LvqZN'></bdo><ul id='LvqZN'></ul>