if redirect..

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
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

if redirect..

Post by ol4pr0 »

I would like to create just one page wich redirects by lever or group.

So if group == 1 .. bla bla

Code: Select all

redirect("location: somepage.php");
how would i do such a thing.

these are the codes i use to know which lever / group a user is.

Code: Select all

// by group
<?php
  include_once ("../auth.php");
  include_once ("../authconfig.php");
  include_once ("../check.php"); 

  if (!($check['team']=='Group 1') 
        && !($check['team']=='Group 3')
           &&!($check['team'] =='Group 2'))
  {
    echo 'You are not allowed to access this page.';
    exit();
  }
?>

// by level

<?php
  include_once ("../auth.php");
  include_once ("../authconfig.php");
  include_once ("../check.php"); 

  if (($check['level'] < 4) || ($check['level'] > 6))
  {
    echo 'You are not allowed to access this page.';
    exit();
  }
?>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Well have you tried using header() instead of echo()? O_o

-Nay
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

duh...

what i basicly mean is...

can i just do it like this ?

Code: Select all

// by group
<?php
  include_once ("../auth.php");
  include_once ("../authconfig.php");
  include_once ("../check.php");

  if (!($check['team']=='Group 1')
        && !($check['team']=='Group 3')
           &&!($check['team'] =='Group 2'))
  {
    header("location: gouppage.php");
    exit();
  }


// by level

  if (($check['level'] < 4) || ($check['level'] > 6))
  {
    header("location: leverpage.php");
    exit();
  }
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well that worked.....

for the archive.... if anybody should need it

Code: Select all

if (!($check['team']=='Group 1')
        && !($check['team']=='Group 3')
           &&!($check['team'] =='Group 2'))
  {
    header("location: grouppage.php");
    exit();
  }

else {

// by level

  if (($check['level'] < 4) || ($check['level'] > 6))
  {
    header("location: levelpage.php");
    exit();
  } 
}
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

Works fine as long as you don't send anything (even spaces) to the browser before the header("location: page.php");

Dr Evil
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

meaning ?
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

Meaning you can not send any content to a browser such as:
<html>
<Head>
...

And the ask it to redirect with header("location: page.php");

This is server script redirect which takes place without the user seeing the page. If you want to redirect after showing the user something use javascript or html reload.

more info info in the [php_man=header]manual[/php_man]
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well for now it works fine... so i guess its all oke.. however i seem to have trouble gettting the Group 4 redirected to a other page...

Maby you got a answer for that one....

Code: Select all

//Group 4 keeps going to grouppage.php


<?php
  include_once ("../auth.php");
  include_once ("../authconfig.php");
  include_once ("../check.php");

  if (!($check['team']=='Group 1')
        && !($check['team']=='Group 2')
           &&!($check['team'] =='Group 3'))
  {
    header("location: grouppage.php");
    exit();
  }

else {

// by level

  if (($check['level'] < 4) || ($check['level'] > 6))
  {
    header("location: levelpage.php");
    exit();
  } 
else {
	if (!($check['team']=='Group 4'))
	  {
	  header("location: siteadmin.php");
	  exit();
	  }
}  
}
?>
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

ol4pr0 wrote:

Code: Select all

//Group 4 keeps going to grouppage.php
This is normal. I do not exactly know what you are trying to do with your program, but the first if says:
If team is not Group 1, 2 or 3 goto grouppage.php.
It exits here, so your program never gets to:
if (!($check['team']=='Group 4'))
I would rethink the if ... else logic.
Or give us a simple explanation of what you need to do.

Good Luck
Post Reply