Load another page if ...

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
msrox
Forum Newbie
Posts: 7
Joined: Thu Oct 19, 2006 5:12 am

Load another page if ...

Post by msrox »

Hi all
I'm trying to write a PHP that checks a statement and if so, then loads another page in the IE,
For example, I type this url in IE:

http://www.mysite.com/check.php

then check.php checks for example if a file entitled test.txt exists on server then I see http://www.google.com ang If NOT I see for example http://www.yahoo.com,

How can I do it by PHP?
Thanks in advance
msrox
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Code: Select all

if (joe likes tea) {
  header("Location: http://www.yahoo.com.com");
} else {
  header("Location: http://www.google.com");
}
Obivously the IF statement would fail, but you get the idea.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

After using a header redirection always use exit. Code execution or script will continue running.

Code: Select all

if (joe likes tea) {
  header("Location: http://www.yahoo.com.com");
} else {
  header("Location: http://www.google.com");
}
$_SESSION['dont change']='blah';
would change the $_SESSION value as well as extra processing time to complete the current script.

Use:

Code: Select all

if (joe likes tea) {
  header("Location: http://www.yahoo.com.com");
  exit;
} else {
  header("Location: http://www.google.com");
  exit;
}
$_SESSION['dont change']='blah';
Post Reply