PHP How to header-location to a page in a parent directory?

淺唱寂寞╮ 提交于 2019-12-19 16:13:10

问题


I have a first.php page with

header("Location: script/script1.php")

and script1.php has another

header("Location: first.php") 

but it sends me obviously to /script/first.php. Is there a way to redirect it to <root>/first.php instead of <root>/script/first.php?


回答1:


have a try with this:

header("Location: ../first.php")

or use an absolute path or url instead.

Explanation: .. is the unix/linux expression used for 'parent directory'. The Internet is unix land, so that rules applies there too.




回答2:


Instead of: header("Location: ../first.php")

try with this: header("url: ../first.php")

this will change the url.Using location don't work in some cases

Since: '../' is to denote 'parent directory'.So,this will work.




回答3:


You can do this. Redirects back to the Home directory (Root) in '0' seconds -

<?php

     header('Refresh: 0, url = /Root_Dir/');

?>

Replace the 'Root_Dir' with your directory name.



来源:https://stackoverflow.com/questions/13366217/php-how-to-header-location-to-a-page-in-a-parent-directory

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