标头位置在服务器上不起作用,但适用于localhost

标头位置在服务器上不起作用,但适用于localhost

问题描述:

I cant get header location to work on my server, but when i run the script at localhost, everything works fine. It seems the server does not run this line.

header('location:index.php');

Server running linux stack with php 7.2, localhost is running xampp (osx) with php 7.3.

I have several projects on the same server with header location, and those are working fine.

我无法在我的服务器上运行标头位置,但是当我在localhost运行脚本时,一切正常。 似乎服务器没有运行此行。 p>

  header('location:index.php'); 
  code>  pre> 
 
 

使用php 7.2运行linux堆栈的服务器, localhost使用php 7.3运行xampp(osx)。 p>

我在同一台服务器上有几个带有标题位置的项目,这些项目工作正常。 p> div>

you can use

echo "<script> window.location.href = 'index.php'; </script>";

Check the path of your index.php

Also you can try to add this before header.

ob_start(); then after that you can exit()

header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP

Linux server is case sensitive try with uppercase Location this. its better to stop script after the header location so no other script will run afterwards.

header('Location: index.php');  
exit;

header best works with absolute URL's, try using http://...../index.php rather than just the filename index.php and since it is index.php use the parent folder, and with the exit; command for example, if

     Location('http://www.slyde.com/index.php'); 
     exit;
     //should be 
     Location('http://www.slyde.com');
     exit;

and so with relative folders.

     Location('http://www.slyde.com/app/index.php');
     exit;
     //should be 
     Location('http://www.slyde.com/app');
     exit;

i hope this works..

alternative to header() you can use :

echo '<script> location.replace("http://yoursite.com/yourpage.php");</script>';