Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="login_form">
- <?php
- if($_COOKIE['username']!='')
- {
- $cookieUsername = $_COOKIE['username'];
- echo "username cookie is set: $cookieUsername <br />";
- $verified=true;
- //set $verified boolean to true, because even
- }
- //be ready to accept username/password for login, sent by previous page
- else if(isset($_POST['login_username']))
- {
- $login_username=$_POST[login_username];
- $login_password=$_POST[login_password];
- //connecting to db servers
- $dbCon=mysql_connect('localhost','root','');
- //connecting to our db
- $selDB=mysql_select_db('test',$dbCon);
- if(!$dbCon || !$selDB)
- {
- exit("<br /> ! Error connecting DataBase or DataBase server for login authentication !<br />");
- }
- $getUsers=mysql_query("SELECT username,password FROM users");
- if(!$getUsers)
- {
- exit("<br /> !! unable to fetch user accounts from database !! <br />");
- }
- $verified = false;
- while($row=mysql_fetch_array($getUsers))
- {
- $username=$row['username'];
- $password=$row['password'];
- echo $username." | ".$password."<br />";
- if(($username == $login_username) && ($password == $login_password))
- {
- echo "<br />--LOGIN SUCCESSFUL--<br />";
- $verified = true;
- setcookie('username',$username,259200); //3 days , in seconds
- setcookie('password',$password,259200);
- //move the values to the set cookies again now, the following way, when followed,
- // we don't need to refresh the page to be able to use the cookies.
- $_COOKIE['username'] = $username;
- $_COOKIE['password'] = $password;
- }
- }
- if(!$verified)
- echo "Wrong username / password<br />";
- }
- //show form only if user not verified
- if(!$verified)
- {
- ?>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
- Username <input class="lico" type="text" name="login_username" /><br />
- Password <input class="lico" type="password" name="login_password" /><br />
- <input type="image" value="submit" src="../images/submit_button.png" /><br />
- <a href="registration.php" title="Sign Up for a new client account">Sign Up for new account</a><br />
- </form>
- <?php
- //end of if(!$verified) statement
- }
- ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement