Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?PHP
  2. /* Turn error reporting for securility purposes */
  3. error_reporting(0);
  4.  
  5. /* Starts the session */
  6. session_start();
  7.  
  8. /*Checks if session exist or not.*/
  9. if ($_SESSION['username']!=NULL and $_SESSION['password']!=NULL)
  10. {
  11.     /*if it doesn't exist then go to the user's page*/
  12.     echo "<script>window.location='user.php';</script>";
  13.     exit;
  14. }
  15.  
  16. /*if data was submited*/
  17. if ($_REQUEST['submit'] == 'submit')
  18. {
  19.     /* Get data from web form */
  20.     $username = $_REQUEST['username'];
  21.     $password = $_REQUEST['password'];
  22.  
  23.     /*create the key out of the username password (concept) */
  24.     $key = $username[0] . $username[1] . $username[2] . $password[3] . $password[2];
  25.    
  26.     /* encypts password */
  27.     $cppassword = crypt($password,$key);
  28.    
  29.     $dbuser="Guest";
  30.     $dbpass="guest";
  31.     $dbname="bktc";
  32.  
  33.     /*
  34.       Connects to the database using guest login
  35.       Guest login can only use the select function
  36.     */
  37.     $chandle = mysql_connect("localhost", $dbuser, $dbpass) or die("Connection Failure to Database");
  38.     mysql_select_db($dbname,$chandle) or die($dbname . " not found." . $dbuser);
  39.  
  40.     /* Get the user from the database */
  41.     $sqlcomm = "SELECT * FROM 'users'";
  42.     $results = mysql_query($sqlcomm) or die(mysql_error());
  43.  
  44.     while($row = mysql_fetch_array($rersult)
  45.     {
  46.         /*Check if the user info match the database or not*/
  47.         if ($row['USERNAME'] == $username) and ($row['PASSWORD'] == $cpassword))
  48.         {
  49.             /* Create a session for the user */
  50.             session_cache_limiter('private');
  51.             $cache_limiter = session_cache_limiter();
  52.             /*set expiration, username and password into the session */
  53.             $session_expire = session_cache_expire();
  54.             $_SESSION['username']=$username;
  55.             $_SESSION['password']=$cpassword;
  56.             $_SESSION['group'] = $row['GROUP'];
  57.             /* redirect you to the user page */
  58.             echo "<script>window.location='user.php';</script>";
  59.             exit;
  60.         }
  61.     }
  62.  
  63.     /* Give them an error */
  64.     echo "Username or password is invaild.<br><br>";
  65.    
  66. }
  67. ?>
  68.  
  69. <html>
  70. <form name="loginform" method="post" action="login.php">
  71. Username: <input type=text name="username"><br>
  72. Password: <input type="password" name="password"><br>
  73. <input type="submit" value="Login">
  74. <input type="hidden" value="submit" name="submit">
  75. </form>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement