simple question

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
halfabag
Forum Newbie
Posts: 2
Joined: Wed Nov 06, 2002 10:48 am

simple question

Post by halfabag »

I've worked with ASP for a number of years and have just made the switch to PHP because,well, it's better, but anyway... in ASP there's a method you can use to transfer output to another page ie.:

Response.Redirect "http://......"

This sends the page listed in the argument to the client's browser.
Is there an equivalent to this in PHP? I've tried using headers ie:

header (location: "http://.....");

But that only works at the beginning of the page. I want to be able to move the user to a page based on a conditional statement ie.

If (blah){
then load this page...
} else{
load this page.....

}

Any help would be great!

Thanks
1/2abag
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

But that only works at the beginning of the page.
not quite. It only works before any content-output.
As long as you don't output anything (see also Sticky: Before Post Read: Warning: Cannot add header information) you can use header('location:....'); anywhere.

also take a look at the include(), require(), include_once() and require_once() manual-pages. Maybe even virtual()
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

I use the Include or the include once. For example this is what i use for access to some of my games.

First off, when they sign into my page one of the variables that is checked and sessioned is a one i give the name of $fast. If the $fast=y then then are do not have to have a starting password emailed to them but rather use their reged password.
<HR>

if ($fast==Y) {

include ("fast/gamea.php");
} // end of the fast area.
else
{

include ("normal/gamea.php");
}
halfabag
Forum Newbie
Posts: 2
Joined: Wed Nov 06, 2002 10:48 am

Thanks!

Post by halfabag »

Both approaches worked like charms!
Post Reply