Asked
Viewed
70.2k times

Hi guys I want to redirect to a page from an if statement i.e without the user doing anything

if condition==a then
got to page
else
got to other page
end if

any help would be great!

add a comment
0

6 Answers

  • Votes
  • Oldest
  • Latest
Answered
Updated
<?php
if( $something ){
   Header("Location: somewhere.php");
} else {
   Header("Location: [http://www.google.com](http://www.google.com)");
}
?>
add a comment
0
Answered
Updated
if (conditiona) {
include ('page_a');
}
else {
include ('page_b');
]

of course thats not redirecting but it is including the page based on an if

add a comment
0
Answered
Updated

hi ,

There's plenty of ways, some more 🙂
PHP + JavaScript ways :

if($flag == 'blabla')
   print "<script language="Javascript">document.location.href='page_a.php' ;</script>";
else
   print "<script language="Javascript">document.location.href='page_b.php' ;</script>";
if($flag == 'blabla')
   print "<script language="Javascript">document.location.replace('page_a.php');</script>";
else
   print "<script language="Javascript">document.location.replace('page_b.php');</script>";

those can work at any level in the script, in any case but JavaScript support must be activated in the client.

add a comment
0
Answered
Updated

and another way is to use meta tags

if($flag == "something") {
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=page_1.php\">";
} else {
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=page_2.php\">";
}

This way can be altered in how long it takes and it won't be affected by the headers, so it can be placed anywhere

add a comment
0
Answered
Updated

Hi evereybody,
Hi Vincent
thanks! 🙂

to me ,yours and Typhon's one are the ones wich have fewest inconvenients 🙂
anyone else? 🙂
choosing one depends on the circumstances in fact.

add a comment
0
Answered
Updated

Thanks guys really appreciate the help worked a charm-
im using vincents! 😁

add a comment
0