redirect index.php to another page

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
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

redirect index.php to another page

Post by tarja311 »

hey all.

i have an index.php page that contains the following code :

Code: Select all

switch( $show )
{ 
   	case "login"; require( "login.php" ); break;
   	case "logout"; require( "logout.php" ); break;
	case "home"; require( "home.php" ); break;
}
this part works fine. the problem is, when i visit my website ( eg: http://mywebsite.com/ ) i receive a blank index.php page. This means i have to refer everybody to http://mywebsite.com/?show=login. ( i can't perform any output inside index.php or it will show in every page ).

If i set a redirection inside index.php, this also affects all my pages. Is there a way i can make this work so it redirects to the login page when a user visits http://mywebsite.com/ and not touch all the other pages ?

thanks

--tarja
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

put a default in that switch statement so that when $show doesn't match anything you have, it will direct to the login page.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
switch( $show )
{
  case "login":
    require( "login.php" ); 
    break;

  case "logout": 
    require( "logout.php" ); 
    break;

  case "home":
    require( "home.php" ); 
    break;

  default: 
    // Do what default is if $show is not found
}
?>
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

Post by tarja311 »

That worked. Thanks. :)
Post Reply