php - Using login data to direct user traffic -


i need redirect please. have piece of code , redirect user specific page. table contains username , password contain third piece of data, org name. each org have own page. --i added name of company in line 17 keep getting echo @ bottom. great.

$dbc = dbconnect();  $username = "exampleuser"; $sql = "select 'password' users 'username' = '$username';"; $result = mysql_query($sql, $dbc); //run query     if ($result) {         $row = mysql_fetch_assoc($result);         $password = $row['password'];          //   echo '<h2>result found '.$password.'</h2>'.php_eol;         $mypassword = $_post['password'];         $row = mysql_fetch_assoc($result);         //$password = $row['password'];         //match passwords             if($mypassword == $password){                 //decide send user depending on company column:                 $privilege = $row['company'];                 if($privilege == "companyname"){                     header( 'location: admin1.php' );                 }                 if($privilege == "user"){                     header( 'location: user.php' );                 }                 if($privilege == "other"){                     header( 'location: other.php' );                 }         exit; //this tells php stop executing redirect     }else{         echo "wrong username/password, try again";     }  } 

basically redirects in php done using header function

for example, call this:

header( 'location: http://google.com' ); 

will redirect user google.com

knowing piece of info we'll use redirect user depending on information fetch database,

let's have user's password in post variable called mypassword

$mypassword = $_post['password']; $row = mysql_fetch_assoc($result);     $password = $row['password'];     //match passwords     if($mypassword == $password){         //decide send user depending on privilege column:         $privilege = $row['privilege'];         if($privilege == "admin"){             header( 'location: admin.php' );         }         if($privilege == "user"){             header( 'location: user.php' );         }         if($privilege == "other"){             header( 'location: other.php' );         }         exit; //this tells php stop executing redirect     }else{         echo "wrong username/password, try again";     } } else {     echo '<h2>no user found, or error: '.mysql_error().' </h2>'; } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -