Header location not working properly

流过昼夜 提交于 2019-11-29 12:47:42

You are using file paths which is not working with header location. You are supposed to use urls.

It's best practice to use absolute urls in header location. PHP documentation says:

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. (Source)

Also always exit the script afterwards because otherwise in my experience in certain circumstances code that comes after the redirect might still be executed. So a good example would look like this:

header("location:http://www.mysite.com/path/to/myfile.php");
exit;

Often you would use a server variable for this case:

$url = $_SERVER["HTTP_HOST"]."/path/to/myfile.php";
header("location:".$url);
exit;

Cheers!

header('Location: ' . $filePath);

SITE_ROOT is the location of the htdocs directory on the server; but header Location should be the path to the file relative to the htdocs directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!