简体   繁体   English

PHP无法正确重定向

[英]php doesn't redirect correctly

I'm running a apache2 server on my raspberry pi that's hosting my website. 我在树莓派上运行一个apache2服务器,该服务器托管我的网站。 By clicking on a link on my website i'm able to change some values in a textfile. 通过单击我网站上的链接,我可以更改文本文件中的某些值。

Now everything works just fine but when the link in my script redirects to the homepage, there seems to be something going wrong. 现在一切正常,但是当我脚本中的链接重定向到主页时,似乎出了点问题。

After redirecting the url isn't 192.168.1.101/index.php , instead it stays 192.168.1.101/scripts/beheerSOD.php?sproeier=1 重定向后的网址不是192.168.1.101/index.php ,而是192.168.1.101/scripts/beheerSOD.php?sproeier=1

If I refresh the page the url changes to 192.168.1.101/index.php but the script also executes again 如果刷新页面,URL会更改为192.168.1.101/index.php,但脚本也会再次执行

Does someone know what's going on? 有人知道发生了什么吗?

Thank you in advance! 先感谢您!

HTML link to script (index.php) 脚本的HTML链接(index.php)

<a href="scripts/beheerSOD.php?sproeier=1">Klik op mij!</a>

Script that redirects in the end (scripts/beheerSOD.php) 最后重定向的脚本(scripts / beheerSOD.php)

<?php
if(isset($_GET['sproeier'])){

    $sproeier = $_GET['sproeier'];
    $SODtxt = file_get_contents('../SOD.txt');
    $sproeierIO = $SODtxt{($sproeier-1)};
    if($sproeierIO=="0"){
        $sproeierIO="1";
    }
    else{
        $sproeierIO="0";
    }
    $eerst = substr($SODtxt,0,$sproeier-1);
    $laatst = substr($SODtxt,$sproeier,strlen($SODtxt));
    $SODtxt = $eerst.$sproeierIO.$laatst;
    file_put_contents('../SOD.txt', $SODtxt);
    header("Location: http://192.168.1.101/index.php");
}

?> ?>

尝试将标头语句放在脚本的顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM