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 语句被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                    <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>