Auto?

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
User avatar
Gavski
Forum Newbie
Posts: 19
Joined: Thu May 16, 2002 2:30 pm
Location: UK

Auto?

Post by Gavski »

I want to build a page that automatically transfers me to other pages-eg

switch()
{
case 1:
go to a url;
break
case 2:
go to another url;
break
.........etc.

Problem:- I don't want to display links to the URL's, I want the page to automatically send me to the URL's

Surely there must be some PHP code that allows for this

Many thanks.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If the page automatically sends you to a particular page but you don't tell it which page to go to how does it know where to go?

I'm mildly confused by what you're trying to do. A little more detail wouldn't hurt - What are you trying to achieve and why are you trying to do it?

Mac
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Problem:- I don't want to display links to the URL's, I want the page to automatically send me to the URL's
If what you mean is that you don't want the user to see the url he or she is being shipped off too, I suspect PHP is NOT going to get the job done. Additionally, most browsers show the user the url they are headin' for in the address bar. If you can use Javascript to affect this in someway, then you would have your answer eh? As a matter of fact, if you want to use some evil pop-up, you should be able to control whether or not it shows the address bar. I think that may be the direction you want to go.

Later on,
BDKR
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Code: Select all

switch( $variable ) {
  case 1:
    header("Location: page1.php");
    exit;
    break;
  case 2:
    header("Location: page2.php");
    exit;
    break;
  case 3:
    header("Location: page3.php");
    exit;
    break;
  default:
    break;
}
If the variable is equal to 1, then you'll get sent to page1.php, 2 and you're sent to page2.php, etc. Just remember you can't output anything to the page before you use the header() function. Also you probably don't need to put the exit and break statements in; I'm just paranoid.
User avatar
Gavski
Forum Newbie
Posts: 19
Joined: Thu May 16, 2002 2:30 pm
Location: UK

Sorry

Post by Gavski »

Sory if this seemed vague, Randomengy's got it though, yes header() is just what I'm looking for.

I wanted to post a variable to the page and depending on the value of that variable, to be sent (automatically) to another page(of course that page would be given a specific URL in the switch() routine.

thanks for your replys
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post by gnu2php »

Don't know if this helps or not, but you could try a more concise approach:

Code: Select all

$pages = array('page1.php', 'page2.php', 'page3.php');

if (in_array($_GETї'page'], $pages))
	header('Location: '.$_GETї'page']);
Post Reply