Page 1 of 1

if redirect..

Posted: Mon Feb 09, 2004 9:12 am
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();
  }
?>

Posted: Mon Feb 09, 2004 9:32 am
by Nay
Well have you tried using header() instead of echo()? O_o

-Nay

Posted: Mon Feb 09, 2004 9:41 am
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();
  }

Posted: Mon Feb 09, 2004 9:51 am
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();
  } 
}

Posted: Mon Feb 09, 2004 10:36 am
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

Posted: Mon Feb 09, 2004 10:46 am
by ol4pr0
meaning ?

Posted: Mon Feb 09, 2004 10:59 am
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.

Posted: Mon Feb 09, 2004 11:13 am
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();
	  }
}  
}
?>

Posted: Mon Feb 09, 2004 12:31 pm
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