Advertisement
Guest User

Untitled

a guest
May 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <div class="login_form">
  2.                 <?php
  3.                
  4.                     if($_COOKIE['username']!='')
  5.                     {
  6.                         $cookieUsername = $_COOKIE['username'];
  7.                         echo "username cookie is set: $cookieUsername <br />"; 
  8.                        
  9.                         $verified=true;
  10.                        
  11.                         //set $verified boolean to true, because even
  12.                     }
  13.                
  14.                     //be ready to accept username/password for login, sent by previous page
  15.                     else if(isset($_POST['login_username']))
  16.                     {
  17.                             $login_username=$_POST[login_username];
  18.                             $login_password=$_POST[login_password];
  19.                            
  20.                              //connecting to db servers
  21.                               $dbCon=mysql_connect('localhost','root','');
  22.                               //connecting to our db
  23.                               $selDB=mysql_select_db('test',$dbCon);
  24.                              
  25.                               if(!$dbCon || !$selDB)
  26.                               {
  27.                                 exit("<br /> ! Error connecting DataBase or DataBase server for login authentication !<br />");
  28.                               }
  29.                              
  30.                               $getUsers=mysql_query("SELECT username,password FROM users");
  31.                               if(!$getUsers)
  32.                               {
  33.                                 exit("<br /> !! unable to fetch user accounts from database !! <br />");
  34.                               }
  35.                              
  36.                               $verified = false;
  37.                              
  38.                               while($row=mysql_fetch_array($getUsers))
  39.                               {
  40.                                     $username=$row['username'];
  41.                                     $password=$row['password'];
  42.                                    
  43.                                     echo $username." | ".$password."<br />";
  44.                                    
  45.                                     if(($username == $login_username) && ($password == $login_password))
  46.                                     {
  47.                                         echo "<br />--LOGIN SUCCESSFUL--<br />";
  48.                                         $verified = true;
  49.                                         setcookie('username',$username,259200); //3 days , in seconds
  50.                                         setcookie('password',$password,259200);
  51.                                         //move the values to the set cookies again now, the following way, when followed,
  52.                                         // we don't need to refresh the page to be able to use the cookies.
  53.                                         $_COOKIE['username'] = $username;
  54.                                         $_COOKIE['password'] = $password;
  55.                                     }
  56.                                
  57.                              }
  58.                              
  59.                             if(!$verified)
  60.                                 echo "Wrong username / password<br />";
  61.                        
  62.                     }
  63.                    
  64.                    
  65.                     //show form only if user not verified
  66.                     if(!$verified)
  67.                     {
  68.                        
  69.                
  70.                 ?>
  71.                 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  72.                 Username <input class="lico" type="text" name="login_username" /><br />
  73.                 Password <input class="lico" type="password" name="login_password" /><br />
  74.                 <input type="image" value="submit" src="../images/submit_button.png" /><br />
  75.                 <a href="registration.php" title="Sign Up for a new client account">Sign Up for new account</a><br />
  76.                 </form>
  77.                
  78.                 <?php
  79.                 //end of if(!$verified) statement
  80.                     }
  81.                
  82.                 ?>
  83.                 </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement