Forum Moderators: coopster

Message Too Old, No Replies

autoredirect

send user to a new page

         

mhbweb

6:54 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



hi all,

id like to know if there is a way of, as the result of a conditional statement sending the user automatically to two different urls without them having to hit a link.

eg/

(password routine)

sucess -----> www.thisurl.com

failure ------> www.orthisurl.com

i hope that makes sense.

jatar_k

6:55 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what would you like to use as your condition?

if (condition1) {
header('Location: www.thisurl.com');
} else {
header('Location: www.orthisurl.com');
}

mhbweb

7:13 pm on Oct 4, 2004 (gmt 0)

10+ Year Member



i wondered about header() but cant that only be used at the very begining of the document? I need this to happen further down in the document. I hope im making sense.

id post a code snippet but its just an idea at the moment.. i mean kinda like this, which looks like what youve suggested, but doesnt seem to work.

if (!$continue) {
header('Location: www.site.com/next.php');
}else {
header('Location: www.site.com/fail.php');
}

jatar_k

7:31 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> only be used at the very begining of the document

not really

It must be used before there is any output to the browser. It doesn't matter where in the script it occurs.

Adrian2k4

12:00 am on Oct 5, 2004 (gmt 0)

10+ Year Member



the header() function only works if nothing has yet been sent to the browser. so there isn't allowed to be any html before the php.
if you echo/print stuff before you decide if you want to redirect, use output buffering.
that way nothing is sent to the browser untill you flush the output buffer.

put ob_start(); at the beginning of the script to start buffering.

use ob_flush(); at the end of the script to flush the buffer to the browser.

see also:
[php.net...]

mhbweb

7:31 pm on Oct 9, 2004 (gmt 0)

10+ Year Member



thanks for your help folks, been away a few days so apologies for hte delayed reply.

ill give have a play and try to learn the concept from what you have suggested :)

ergophobe

8:44 pm on Oct 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you did want to start output and then serve up a different page on success/failure, you can always just do

if (!$continue) {
include('next.php');
}else {
include('fail.php');
}

Obviously that's the same URL in both cases, but that's not necessarily a problem.