Forum Moderators: coopster

Message Too Old, No Replies

HTTP redirects based on URL

         

aspr1n

3:44 pm on May 5, 2003 (gmt 0)

10+ Year Member



Thought I'd share this on as it's taken me a while to figure it out, if anyone knows of an easier way please let me know.

I wanted to do an http redirect if the user's authentication had failed:

$NewPage = 'login'; 
if(!authenticated() ) {
$NewURL = preg_replace( "[\w+(?=\.php)]", $NewPage, $_SERVER[ "SCRIPT_URI" ] );
header( "location: $NewURL\r\n" );
}
else
do something...

asp

toadhall

4:15 pm on May 5, 2003 (gmt 0)

10+ Year Member



This is a lot less work:

if(!authenticated() ) {
echo '<meta http-equiv="refresh" content="1; url=path/to/file.ext">';
} else {
echo 'do something...';
}

T

aspr1n

4:58 pm on May 5, 2003 (gmt 0)

10+ Year Member



if (!authenticated() ) {
echo '<meta http-equiv="refresh" content="1; url=path/to/file.ext">';
}
else
{
echo 'do something...';
}

Yep certainly is - but I'd need to know what "path/to/" was.

asp

toadhall

5:55 pm on May 5, 2003 (gmt 0)

10+ Year Member



The "path/to" would be the same as the path to the script you're running - the path extracted from SCRIPT_URI.

'login.php' must reside at the end of that same path as you're slipping it in the place of the original file name via the preg_replace().

Seeing as the two files are residing in the same directory, just enter login.php in the meta refresh, it will redirect to that file if (!authentication()).

T