Page 1 of 1

Load another page if ...

Posted: Fri Oct 20, 2006 5:52 am
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

Posted: Fri Oct 20, 2006 6:29 am
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.

Posted: Fri Oct 20, 2006 7:13 am
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';