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
[SOLVED] Newbie question on calling a url from PHP
Moderator: General Moderators
-
rbmcauliffe
- Forum Newbie
- Posts: 3
- Joined: Sun Nov 16, 2003 4:02 pm
-
rbmcauliffe
- Forum Newbie
- Posts: 3
- Joined: Sun Nov 16, 2003 4:02 pm
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
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
The functionality you're looking for is part of [php_man]header[/php_man] I believe.
Just be aware that you can have no output before this function or it will return an error (or sometimes simply not work).
Code: Select all
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
?>-
rbmcauliffe
- Forum Newbie
- Posts: 3
- Joined: Sun Nov 16, 2003 4:02 pm