[SOLVED] Newbie question on calling a url from PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rbmcauliffe
Forum Newbie
Posts: 3
Joined: Sun Nov 16, 2003 4:02 pm

[SOLVED] Newbie question on calling a url from PHP

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

include("somepage.php");

Note that this must be done before any output to the browser.
rbmcauliffe
Forum Newbie
Posts: 3
Joined: Sun Nov 16, 2003 4:02 pm

Post 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
Quietus
Forum Newbie
Posts: 16
Joined: Sat Nov 15, 2003 1:59 am

Post 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).
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Crap, sorry RBM, I misread the question. And cheers quietus.
rbmcauliffe
Forum Newbie
Posts: 3
Joined: Sun Nov 16, 2003 4:02 pm

Post by rbmcauliffe »

No problem Paddy and "Thanks" Quietus. That did the trick.

Richard
Quietus
Forum Newbie
Posts: 16
Joined: Sat Nov 15, 2003 1:59 am

Post by Quietus »

You're welcome.

Now pass me my cape :lol:
Post Reply