Re: setcookie then redirect

From: Date: Thu, 11 Jul 2002 13:52:21 +0000
Subject: Re: setcookie then redirect
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-107124@lists.php.net to get a copy of this message
Hi David, Your question has seen much debate in this newsgroup. I had much the same problem and solved it by writing the following function: /** * wrapper for header( "Location: url" ) */ function redirect( $url, $showMoved=false ) { // set refresh to target $url header( "Refresh: 0; url=$url" ) ; // show page has moved if ( $showMoved ) { echo "<html><head><title>Moved to $url</title></head><body><p>This page has moved to <a href=\"$url\">$url</a>.</body></html>" ; } // exit current script exit ; } Since it doesn't use header( "Location: ..." ) you are able to write your cookies before you redirect. It's about the most elegant solution to your problem, short of redesigning your pages. Of course, I have noticed that if you don't supply the html ($showMoved) Opera chokes. IE and Netscape seem to handle it fine and I haven't tested Mozilla yet. Hope it helps! Cord "David Busby" <busby@pnts.com> wrote in message news:3D2CC493.7020109@pnts.com... > List, > I'm trying to set a cookie like this: > <?php > function redirect() { [..snip..]

« previous php.general (#107124) next »