Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h2>Login</h2>
- <br/><br/>
- <?php
- //Checks if there is a login cookie
- $cookieID = 'ID_kebax_dk_sell';
- $cookieKey = 'Key_kebax_dk_sell';
- if(isset($_COOKIE[$cookieID])) {
- //if there is, it logs you in and directes you to the members page
- $username = $_COOKIE[$cookieID];
- $pass = $_COOKIE[$cookieKey];
- $check = mysql_query("SELECT * FROM sell_users WHERE nickname = '".$username."'")or die(mysql_error());
- while($info = mysql_fetch_array( $check )) {
- if ($pass != $info['password']) {
- //fail -> nothing happens.
- } else {
- $_SESSION['username'] = $username;
- echo 'Already logged in as '.$username;
- echo "<meta http-equiv=refresh content=\"1; URL=index.php\">";
- }
- }
- } else if(isset($_POST['login'])) { // if form has been submitted
- // makes sure they filled it in
- if(!$_POST['username'] | !$_POST['password']) {
- die('You did not fill in a required field.');
- }
- // checks it against the database
- if (!get_magic_quotes_gpc()) {
- $_POST['email'] = addslashes($_POST['email']);
- }
- $check = mysql_query("SELECT * FROM sell_users WHERE nickname = '".$_POST['username']."'")or die(mysql_error());
- //Gives error if user dosen't exist
- $check2 = mysql_num_rows($check);
- if ($check2 == 0) {
- die('That user does not exist in our database.');
- }
- while($info = mysql_fetch_array( $check )) {
- $_POST['password'] = stripslashes($_POST['password']);
- $info['password'] = stripslashes($info['password']);
- $_POST['password'] = md5($_POST['password']);
- //gives error if the password is wrong
- if ($_POST['password'] != $info['password']) {
- die('Incorrect password, please try again.');
- }
- else {
- // if login is ok then we add a cookie
- $_POST['username'] = stripslashes($_POST['username']);
- $hour = time() + 3600;
- setcookie(ID_kebax_dk_sell, $_POST['username'], $hour);
- setcookie(Key_kebax_dk_sell, $_POST['password'], $hour);
- $_SESSION['username'] = $_COOKIE['ID_kebax_dk_sell'];
- $username = $_COOKIE['ID_kebax_dk_sell'];
- //then redirect them to the members area
- echo '<br/>Logged in successfully as '.$username.'...';
- //ob_end_flush();
- echo "<meta http-equiv=refresh content=\"1; URL=index.php\">";
- }
- }
- }
- else {
- // if they are not logged in
- echo ('
- <form method="post" action="">
- <input name="username" placeholder="Username..." type="text" maxlength="15" /><br/><br/>
- <input name="password" placeholder="Password..." type="password" maxlength="20" /><br/><br/>
- <input name="login" type="submit" value="Login" style="width:100px;">
- </form>
- ');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement