Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- ///must have this session_start, or it wont work
- session_start();
- //get the database connection
- require_once("db.php");
- //see if they are already logged in, if so they go to members page
- if(isset($_SESSION['logged']) == true) {
- header("Location: index.php");
- }
- // see if you have submitted the log in form
- if (isset($_POST['submit'])) {
- // see if they filled in username and password
- if(!$_POST['username'] || !$_POST['password']) {
- echo "<body bgcolor='black' text='white' link='white' alink='white' vlink='white'>You did not fill in a required field.</body>";
- }
- // encrypt the password, must have this function in registering script! or they will never match.
- function enchsetenev($toencode,$times)
- {
- $salt = 's+(_a*';
- for($zo=0;$zo<$times;$zo=$zo+1)
- {
- $toencode = hash('sha512',$salt.$toencode);
- $toencode = md5($toencode.$salt);
- }
- return $toencode;
- }
- $password = enchsetenev("{$_POST['password']}",500);
- // changing the $_POST so its easier to type, etc.
- $username = ($_POST['username']);
- $ip = $_SERVER['REMOTE_ADDR'];
- // checks it against the database
- $check = mysql_query("SELECT username, password FROM user WHERE username = '$username' AND password='$password'")or die(mysql_error());
- $now = mysql_query("SELECT COUNT(id) FROM `user` WHERE online != 'Offline' AND ip = '{$ip}'") or die(mysql_error());
- // checks if you have 2 accounts logged on already
- $nw = mysql_fetch_array($now);
- if($nw['COUNT(id)'] == 2) { echo "<body bgcolor='black' text='white' link='white' alink='white' vlink='white'>You already have 2 accounts on already. Log one out first</body>"; }
- //Gives error if user doesn't exist
- $check2 = mysql_num_rows($check);
- if ($check2 == 0) {
- echo "<body bgcolor='black' text='white' link='white' alink='white' vlink='white'>That username / password combination does not exist.</body>";
- }
- // if login is ok then we add a cookie
- $_SESSION['username'] = ($_POST['username']);
- $_SESSION['logged'] = true;
- // update online status
- $q=mysql_query("UPDATE `user` SET online='At Home',ip='{$ip}' WHERE username='{$_SESSION['username']}'") or die(mysql_error());
- //then redirect them to the members area
- header("Location: index.php");
- } else {
- ?>
- <body bgcolor='black' text='white' link='white' alink='white' vlink='white'>
- <table bgcolor='black' bordercolor='1166ff' border='1' align='center'><tr><td>
- <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="POST">
- <table border="0" align="center">
- <tr><td colspan="2"><h3 align="center"><u>Login</u></h1></td></tr>
- <tr><td>Username:</td><td>
- <input type="text" name="username" maxlength="40">
- </td></tr>
- <tr><td>Password:</td><td>
- <input type="password" name="password" maxlength="50">
- </td></tr>
- <tr><td colspan="2" align="right">
- <input type="submit" name="submit" value="Login">
- </td></tr>
- </table></tr></td></table>
- </form>
- <center><a href='reg.php'>Click Here to Create an Account</a></center></body><?PHP } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement