Re: client redirection

From: Date: Wed, 18 Oct 2000 07:37:54 +0000
Subject: Re: client redirection
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20819@lists.php.net to get a copy of this message
Scott Mebberson writes: > I think that you can use some sort of $HTTP_REDIRECT method maybe(?!?!?) to > redirect the user to a different page. but I understand that this is only > before the header has been sent to the client page. > > What about if you want to redirect the user only if certain conditions > exist. What happens then. I have though of using meta data to do this, but > can meta data be put anywhere in the page? Doesn't it have to be put in the > <head></head> section of the html? > > Is there any PHP redirect method ie > /user_redirect("http://www.whereiwant.com"); > > this would be pretty good. Maybe I am asking for too much. > > thanks > > scott. It has nothing to do with PHP per se; it's just that once output starts, you can't send headers anymore--and since the redirect is a header, there you go. The code is: header("Location: http://www.someserver.com"); <meta> tags must go in the <head>. And they will probably work. With most browsers. :) One way to look at where this sort of code should typically go in a page is: should the script know which page it wants to show to the user before or after it has started printing stuff to the browser? In most cases, the answer will be 'before'. So often, it ends up working out better anyway to hold off on outputting HTML or redirects until you know what to show. If that's not an option, PHP 4 has output buffering--meaning that anything that would normally get sent to the client just gets stored until you decide to send it. So you can send the redirects whenever you like. I haven't played with it much, but I've been told that there is a performance penalty. I have no idea whether it's a significant one or not. Anyway, check out the ob_*() functions: http://www.php.net/manual/ref.outcontrol.php Hope this helps, -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#20819) next »