Problem with header

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
orangeapple
Forum Commoner
Posts: 70
Joined: Tue Jan 06, 2004 1:24 pm
Location: Geneva / Switzerland

Problem with header

Post by orangeapple »

Hi guys !

Have a problem with header. This is a part of my code :

Code: Select all

<?php
 else {

  
     {

    $sql_passe_check = "SELECT * FROM passe WHERE login='$login' and passe='$passe'";
    $result_passe_check = mysql_query($sql_passe_check);
    $passefound = mysql_num_rows($result_passe_check);
    
    while ($row = mysql_fetch_array($result_passe_check))
                  {
                            $privilege=$row['privilege'];

                             }


     //if checkbox not checked (=password)
     if ($changecheck != "1")
      {
        if ($passefound < 1) {
        echo $html1;
        echo '<br /><div align="center"><br /><br /><img src="../media/sign_warning.jpg" width="70" height="70" border="0"><br /><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="3" color="white"><b>Password not correct !<br />Please go back and try again.</b><br /><br /><br /><br /><br /><a href="clients.html"><img src="../media/sign_back.jpg" width="40" height="40" border="0"></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><div>';
        echo $html2;
        exit;
         }


        else {
         //echo $privilege;
         //exit;
        if ($privilege = 1){

header("Location: norestric1.php");
}
        if ($privilege = 2){

header("Location: norestric2.php");
}
        if ($privilege = 3){

header("Location: norestric3.php");
}
        

        exit;
        }

      }

?>
I know that $privilege is properly extracted from the DB because i can echo it.
But with the "if" and "header" conditions, the file redirects always on norestric3.php whatever the value of $privilege is.

Who can explain me what is wrong ?

Thanks !
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

if ($privilege == 1) would work better...
User avatar
orangeapple
Forum Commoner
Posts: 70
Joined: Tue Jan 06, 2004 1:24 pm
Location: Geneva / Switzerland

Post by orangeapple »

:oops: thanks !

...and what would be the syntax, if i want to send the variable to norestric1.php ?

i have seen this code somewere in this forum :

Code: Select all

<?php

header("Location: norestric1.php?$privilege==1"); 

?>
but it doesn't work...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

?privilege=1

And norestric1.php will have to check for $_GET['privilege'] unless you have register_globals On.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

if ($privilege == 1){
header("Location: norestric1.php?privilege=1");
}

call variable as $priviledge if register_globals is off, else call as $_GET['priviledge']
User avatar
orangeapple
Forum Commoner
Posts: 70
Joined: Tue Jan 06, 2004 1:24 pm
Location: Geneva / Switzerland

Post by orangeapple »

Ok, i have :

Code: Select all

<?php

header("Location: norestric1.php?$privilege=1"); 

?>
and this is my norestric1.php file :

Code: Select all

<?php
$privilege=$_GET['privilege'];
echo $privilege;
?>
but it still doesn't work
User avatar
orangeapple
Forum Commoner
Posts: 70
Joined: Tue Jan 06, 2004 1:24 pm
Location: Geneva / Switzerland

Post by orangeapple »

sorry, i made a mistake with $privilege.

Now it works !

Thanks a lot !
Post Reply