header("Location: ...") question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

header("Location: ...") question

Post by tylerdurden »

I'm making heavy use of

Code: Select all

header("Location: $url");
calls on a website of mine and everything's working well.
Now a user contacted me to say that the redirections aren't working. I'm not sure if it's got anything to do with the "header("Location: $url");" code yet, but I think I'd ask the Forum members anyway if there are any known incompatibilities with this method of redirection?
I've tested it in most browsers without problems.

Thanks!
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

On some browsers you can disable redirection.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Maybe somewhere in your script $url gets the wrong url assigned to it? That would explain why the user is getting redirected to the wrong pages.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Penguinboy, where'd you find that out? I couldn't find too much on the topic.
prov
Forum Newbie
Posts: 10
Joined: Thu Mar 25, 2004 9:13 pm
Location: Providence, RI
Contact:

Post by prov »

The header function sends a response to the client, and it's up to the client (i.e. browser) to determine what to do with that directive. Just like if the PHP script echoed a response, for all we know the browser might interpret that to mean "crash now".

Headers are kind of tricky that way. I suggest, under your header function, you echo a link to the intended destination.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Alright, thanks prov.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Not quite. The header function is like anything other php function, it just tells the server to send the information from a different page instead of the original. The browser has nothing to do with it.
The problem is with your code/input, not the browser.
burzvingion
Forum Newbie
Posts: 11
Joined: Sun Apr 18, 2004 2:30 pm

Post by burzvingion »

LiLpunkSkateR wrote:Not quite. The header function is like anything other php function, it just tells the server to send the information from a different page instead of the original. The browser has nothing to do with it.
The problem is with your code/input, not the browser.
Incorrect. Try using cURL sometime on a page that uses a location header. Its up to the browser to get the new page. Some browsers have trouble if you dont use an absolute url, so make sure if you're dynamicly making urls to put $_SERVER['HTTP_HOST'] before the relative location
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

nigma wrote:Penguinboy, where'd you find that out? I couldn't find too much on the topic.
Just look in your browsers settings.
I use Opera, and it allows me to disable redirection.
Post Reply