Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- creating two different sessions in PHP
- <?php
- include("dbconnect.php");
- $con= new dbconnect();
- $con->connect();
- //create and issue the query
- $sql = "SELECT type FROM users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";
- $result = mysql_query($sql);
- //get the number of rows in the result set; should be 1 if a match
- if (mysql_num_rows($result) == 1) {
- $type_num=0;
- //if authorized, get the values
- while ($info = mysql_fetch_array($result)) {
- $type =$info['type'];
- }
- if($type == "admin")
- {
- $_SESSION['type']=1;
- $u = 'welcome.php';
- header('Location: '.$u);
- }
- else
- {
- $_SESSION['type']=$type_num;
- $u = 'welcome.php';
- header('Location: '.$u);
- }
- }
- else {
- //redirect back to loginfailed.html form if not in the table
- header("Location: loginfailed.html");
- exit;
- }
- ?>
- <?php
- session_start();
- ?>
- <html>
- <body>
- <h2>Welcome.</h2>
- <?
- if($_SESSION['type']==1){
- echo "You are of the usertype Admin and your session id is ";
- echo session_id();
- }
- else {
- echo "You are of the usertype Author and your session id is ";
- echo session_id();
- }
- ?>
- </body>
- </html>
- while ($info = mysql_fetch_array($result)) {
- $type =$info['type'];
- echo $type . '<br />';
- }
- echo '<pre>';
- while ($info = mysql_fetch_array($result)) {
- $type =$info['type'];
- print_r($info);
- }
- echo '</pre>';
Add Comment
Please, Sign In to add comment