简体   繁体   中英

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM