Page 1 of 1

[SOLVED] Newbie question on calling a url from PHP

Posted: Sun Nov 16, 2003 4:02 pm
by rbmcauliffe
I am new to php and am trying to use an if/else statement to direct my user to either the page he/she requested or to the log-in page if a condition (either a successful query of the db with their username/password or the existence of a valid session variable) is not met.

I'm not having a problem with the general logic of this. I am, however, having difficulty identifying a php function which allows me to implement this functionality. In general, I'm trying to do the following:

if (condition exists)
{
do_this_function("the requested page")
}
else
{
do_this_function("the log-in page"
}

I'm looking for the 'do_this_function' part.

Any help would be greatly appreciated.

Thanks,

Richard

Posted: Sun Nov 16, 2003 4:05 pm
by Paddy
include("somepage.php");

Note that this must be done before any output to the browser.

Posted: Sun Nov 16, 2003 5:37 pm
by rbmcauliffe
Thanks Paddy.

I'd already tried the include function and, while it works in a fashion, it still doesn't behave the way I was hoping(unless I'm implementing it improperly). Specifically, it seems to wrap a page "inside" my page (as you would expect from the function name) as opposed to simply "going to" the url in the if/else statement.
For instance, the url in the address bar still shows 'mypage' instead of the page that's actually being displayed.


Surely php has another method of simply directing a user to another, completely distinct url, doesn't it?

Richard

Posted: Sun Nov 16, 2003 5:44 pm
by Quietus
The functionality you're looking for is part of [php_man]header[/php_man] I believe.

Code: Select all

<?php
header("Location: http://www.example.com/"); /* Redirect browser */
?>
Just be aware that you can have no output before this function or it will return an error (or sometimes simply not work).

Posted: Sun Nov 16, 2003 5:49 pm
by Paddy
Crap, sorry RBM, I misread the question. And cheers quietus.

Posted: Sun Nov 16, 2003 7:27 pm
by rbmcauliffe
No problem Paddy and "Thanks" Quietus. That did the trick.

Richard

Posted: Mon Nov 17, 2003 1:34 pm
by Quietus
You're welcome.

Now pass me my cape :lol: