Jump to content


Photo

Redirects based on URL variables...


  • Please log in to reply
5 replies to this topic

#1 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 01 October 2006 - 05:12 PM

Hello,

Does anyone know how to invoke a redirect to another html page (error page) based on the condition that a user selects certain variables in the URL. I know an if statement would have to be used, and I would use "if $variable =>.." so greater than or equal to. But I cant think of a way to invoke the redirect.....

Any suggestions?

Thanks a lot,
mkosmosports

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 01 October 2006 - 05:16 PM

Hi,

You have to use the META tag for this

<meta http-equiv="refresh" content="2;url=http://mypage/index2.php">


Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 October 2006 - 05:17 PM

Use the header() function...

<?php

if ($var == 1){
   header("Location: index.php");
}
elseif ($var == 2){
   header("Location: contact.php");
}
else {
   header("Location: error.php");
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 October 2006 - 05:19 PM

If you want to redirect a user use header, For example say you had a login script and then you checked for the logout variabled in the url If you find it you'll redirect the user to the logout page:
if(isset($_GET['logout') && $_GET['logout'] == 'true')
{
    header("Location: logout.php");
}


#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 05:20 PM

Hi,

You have to use the META tag for this

<meta http-equiv="refresh" content="2;url=http://mypage/index2.php">


Not a good idea: http://www.w3.org/QA/Tips/reback

#6 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 01 October 2006 - 05:39 PM

Thanks a lot for your help guys, I've tried the suggested methods and one of them works just the way I want it!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users