Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- function hash($value)
- {
- $salt = "S?@!%)";
- if (is_array($value))
- {
- return md5($salt.serialize($value));
- } else
- {
- return md5($salt.$value);
- }
- }
- if (isset($_POST['username']))
- {
- $username = mysql_real_escape_string($_POST['username']);
- $password = hash($_POST['password']);
- $sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."'";
- $query = mysql_query($sql);
- if (mysql_num_rows($query) > 0)
- {
- $user = mysql_fetch_array($query);
- $_SESSION['hash'] = hash($user);
- $_SESSION['user] = $user;
- } else
- {
- echo "Incorrect Login.";
- }
- } else if (isset($_GET['logout']))
- {
- session_destroy();
- header("Location: index.php");
- }
- if (isset($_SESSION['user']) AND $_SESSION['hash'] == hash($_SESSION['user']))
- {
- echo "Welcome ".$_SESSION['user']['username'];
- } else
- {
- echo "Welcome Guest!";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement