Asked
Viewed
71.3k 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

User

Community

Market

Help Center

Legal

Company

Social Media

\";\nelse\n print \"\";\n```\n\n```php\nif($flag == 'blabla')\n print \"\";\nelse\n print \"\";\n```\n\nthose can work at any level in the script, in any case but JavaScript support must be activated in the client.","upvoteCount":0}],[{"@type":"Answer","url":"https://www.ozzu.com/questions/315016/how-do-you-redirect-to-a-new-webpage-using-php#post-315278","datePublished":"2006-02-22T03:58:08+00:00","dateModified":"2024-07-16T17:17:26+00:00","author":{"@type":"Person","name":"Vincent"},"text":"and another way is to use meta tags\n\n```\nif($flag == \"something\") {\n echo \"\";\n} else {\n echo \"\";\n}\n```\n\nThis way can be altered in how long it takes and it won't be affected by the headers, so it can be placed anywhere","upvoteCount":0}],[{"@type":"Answer","url":"https://www.ozzu.com/questions/315016/how-do-you-redirect-to-a-new-webpage-using-php#post-315285","datePublished":"2006-02-22T05:23:07+00:00","dateModified":"2024-07-16T17:17:26+00:00","author":{"@type":"Person","name":"gisele"},"text":"Hi evereybody,\nHi Vincent\nthanks! 🙂\n\nto me ,yours and Typhon's one are the ones wich have fewest inconvenients 🙂\nanyone else? 🙂\nchoosing one depends on the circumstances in fact.","upvoteCount":0}],[{"@type":"Answer","url":"https://www.ozzu.com/questions/315016/how-do-you-redirect-to-a-new-webpage-using-php#post-315307","datePublished":"2006-02-22T07:15:12+00:00","dateModified":"2024-07-16T17:17:26+00:00","author":{"@type":"Person","name":"Niall Lally"},"text":"Thanks guys really appreciate the help worked a charm-\nim using vincents! 😁","upvoteCount":0}]]}}