Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 365
alecam Avatar asked Nov 13 '12 18:11

alecam


People also ask

What is PHP header location?

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 PHP can do with header () command?

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.

What is content type header in PHP?

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.


3 Answers

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.

like image 158
arkascha Avatar answered Oct 25 '22 04:10

arkascha


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.

like image 23
Kush Bhardwaj Avatar answered Oct 25 '22 02:10

Kush Bhardwaj


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.

like image 32
user7564487 Avatar answered Oct 25 '22 03:10

user7564487