Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // starting the session
- session_start();
- if (isset($_SESSION['uname'])) {
- header("Location: userarea.php");
- } else {
- $dbhost=""; // Host name
- $dbusername=""; // Mysql username
- $dbpassword=""; // Mysql password
- $db_name=""; // Database name
- $tbl_name=""; // Table name
- // Connect to server and select databse.
- mysql_connect("$dbhost", "$dbusername", "$dbpassword")or die("cannot connect to DB");
- mysql_select_db("$db_name")or die("cannot select DB");
- // Get the username and password by POST
- $user = mysql_real_escape_string(stripslashes($_POST['uname']));
- $pass = mysql_real_escape_string(stripslashes($_POST['passwd']));
- $sql="SELECT * FROM $tbl_name WHERE `username`='$user' AND `password`='$pass'";
- $query=mysql_query($sql) or die(mysql_error());
- if(mysql_num_rows($query) == 1)
- {
- $row = mysql_fetch_assoc($query); // mysql_fetch_assoc gets the value for each field in the row
- $_SESSION['uname'] = $row['username']; // second session var
- Header("Location: userarea.php");
- }
- else
- {
- // Username and password are wrong
- Header("Location: index.php");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement