Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2. // starting the session
  3. session_start();
  4.     if (isset($_SESSION['uname'])) {
  5.     header("Location: userarea.php");
  6.     } else {
  7.    
  8.     $dbhost=""; // Host name
  9.     $dbusername=""; // Mysql username
  10.     $dbpassword=""; // Mysql password
  11.     $db_name=""; // Database name
  12.     $tbl_name=""; // Table name
  13.  
  14.     // Connect to server and select databse.
  15.     mysql_connect("$dbhost", "$dbusername", "$dbpassword")or die("cannot connect to DB");
  16.     mysql_select_db("$db_name")or die("cannot select DB");
  17.    
  18.     // Get the username and password by POST
  19.     $user = mysql_real_escape_string(stripslashes($_POST['uname']));
  20.     $pass = mysql_real_escape_string(stripslashes($_POST['passwd']));
  21.  
  22.        
  23.    
  24.     $sql="SELECT * FROM $tbl_name WHERE `username`='$user' AND `password`='$pass'";
  25.     $query=mysql_query($sql) or die(mysql_error());
  26.  
  27.     if(mysql_num_rows($query) == 1)
  28.     {
  29.         $row = mysql_fetch_assoc($query); // mysql_fetch_assoc gets the value for each field in the row
  30.         $_SESSION['uname'] = $row['username']; // second session var
  31.  
  32.         Header("Location: userarea.php");
  33.     }
  34.     else
  35.     {
  36.         // Username and password are wrong
  37.         Header("Location: index.php");
  38.     }  
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement