dsrbb20862 2015-09-06 16:43
浏览 36

PHP重定向if语句

I am using this if statement to redirect a user if the values in a .txt document is 0 but if it is 1 I want nothing to happen however I'm having some issues with my code.

This is my code currently:

$setup = require('setup.txt');

if ($setup === "0") {
    echo '<script type="text/javascript"> window.location = "setup.php"    </script>';
}

The setup.txt document currently contains the value 0.

  • 写回答

3条回答 默认 最新

  • douwen4178 2015-09-06 16:46
    关注

    Use the header function if you have not already sent output to the browser.

    $setup = file_get_contents('setup.txt');
    if ($setup == "0") {
      header('Location: /setup.php');
    }
    

    Since all PHP is executed before the output the site. Use this option first.

    You can not use include() / require() to transfer as a variable, like you have. Use file_get_contents() to achieve the results.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么