Guest User

Untitled

a guest
Sep 18th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. creating two different sessions in PHP
  2. <?php
  3. include("dbconnect.php");
  4. $con= new dbconnect();
  5. $con->connect();
  6. //create and issue the query
  7. $sql = "SELECT type FROM users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";
  8.  
  9. $result = mysql_query($sql);
  10.  
  11. //get the number of rows in the result set; should be 1 if a match
  12. if (mysql_num_rows($result) == 1) {
  13. $type_num=0;
  14. //if authorized, get the values
  15. while ($info = mysql_fetch_array($result)) {
  16. $type =$info['type'];
  17. }
  18.  
  19. if($type == "admin")
  20. {
  21. $_SESSION['type']=1;
  22. $u = 'welcome.php';
  23. header('Location: '.$u);
  24. }
  25. else
  26. {
  27. $_SESSION['type']=$type_num;
  28. $u = 'welcome.php';
  29. header('Location: '.$u);
  30.  
  31.  
  32. }
  33. }
  34. else {
  35. //redirect back to loginfailed.html form if not in the table
  36. header("Location: loginfailed.html");
  37. exit;
  38. }
  39. ?>
  40.  
  41. <?php
  42. session_start();
  43. ?>
  44.  
  45. <html>
  46. <body>
  47. <h2>Welcome.</h2>
  48. <?
  49. if($_SESSION['type']==1){
  50. echo "You are of the usertype Admin and your session id is ";
  51. echo session_id();
  52. }
  53. else {
  54. echo "You are of the usertype Author and your session id is ";
  55. echo session_id();
  56. }
  57. ?>
  58.  
  59.  
  60.  
  61. </body>
  62. </html>
  63.  
  64. while ($info = mysql_fetch_array($result)) {
  65. $type =$info['type'];
  66. echo $type . '<br />';
  67. }
  68.  
  69. echo '<pre>';
  70. while ($info = mysql_fetch_array($result)) {
  71. $type =$info['type'];
  72. print_r($info);
  73. }
  74. echo '</pre>';
Add Comment
Please, Sign In to add comment