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
?
Basically, there are two types of header calls. One is header which starts with string “HTTP/” used to figure out the HTTP status code to send. Another one is the “Location” which is mandatory. replace: It is optional which indicates whether the header should add a second header or replace previous.
What is header() function in PHP? The header() function is an predefined PHP native function. With header() HTTP functions we can control data sent to the client or browser by the Web server before some other output has been sent. The header function sets the headers for an HTTP Response given by the server.
The Content-Type header is used to indicate the media type of the resource. The media type is a string sent along with the file indicating the format of the file. For example, for image file its media type will be like image/png or image/jpg, etc. In response, it tells about the type of returned content, to the client.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With