Akshat Mittal
Akshat Mittal

Reputation: 827

The 'Location' Header is not working at all in PHP

I was working on a PHP code, and had header('Location: '.$location, TRUE, 200);, it did not redirect to $location (Value here was "https://thepiratebay.se/" ). I have listed all the headers present, Please help.

As you can see that the Location header was present but didn't redirect to. Why?

Browsers tested: Chrome, Firefox, IE, Safari.

Headers were (As shown by Chrome):

HTTP/1.1 200 OK
Date: Sat, 25 Aug 2012 15:10:54 GMT
Server: Apache/2.4.2 (Win32) PHP/5.4.4
X-Powered-By: PHP/5.4.4
Location: https://thepiratebay.se/
Content-Length: 5935
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

Upvotes: 2

Views: 4977

Answers (1)

Daniel M
Daniel M

Reputation: 3379

Your mistake is the 200 response code.

Change this line:

header('Location: '.$location, TRUE, 200);

To be

header('Location: '.$location, TRUE, $code);

Where $code is either 301 or 302 (Moved permanently vs Moved temporarily).

Upvotes: 5

Related Questions