简体   繁体   中英

Constantly refreshing page instead of redirecting in PHP

Here is my server structure:

folder_in_root
another_folder/not_root_here
another_folder/nested_script.php
index.php                         #in root
one_script_in_root.php            #in root

I have the following function running in ALL the scripts of the server, whether in root or not:

function notify(){

   (...)

      if ( !(strpos($_SERVER['SCRIPT_NAME'], 'index.php')) && ($feedback["connect_time"] == 0 || $feedback["http_code"] == 404)){
          exit("<meta http-equiv='refresh' content='0' ;url='../index.php'>");
    }


}

This function does not refresh the page if it is inside index.php, which is good, and heads to index.php if not inside index.php WHEN the original script is NOT on root. So, this script works in another_folder/not_root_here , another_folder/not_root_here , index.php but FAILS in one_script_in_root.php because it keeps refreshing one_script_in_root.php over and over again instead of sending the user to index.php . I can't figure out why this happens. Can someone help me please? tyvm.

This meta refresh has a wrong syntax

<meta http-equiv="refresh" content="0; URL=../index.php">

would be correct

index.php is located at root of your domain, so just redirect to /

url="/"

Btw, you can use location header instead.

The best solution would be to just replace index.php with your domainname/ip. This makes the function work on whatever directory you call it.

<meta http-equiv="refresh" content="0; URL=\\www.mydomain.com">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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