Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.89 KB | None | 0 0
  1. <?php
  2.  
  3.  if ( isset($_POST["submit"]) )
  4.  {
  5.      echo "calling before sessions_set_cookie_params" ;
  6.      if ( $_POST["remember"] == "on") // this isn't working for some reason
  7.     {
  8.        // extend expiration date of cookie
  9.        session_set_cookie_params('3600');
  10.        session_set_cookie_params(3600);
  11.        echo "<br/>calling after sessions_set_cookie_params" ;
  12.     }
  13.  }
  14.  require_once("includes/session.php"); //session start ?>
  15. <?php require_once("includes/connection.php"); ?>
  16. <?php require_once("includes/functions.php"); ?>
  17. <?php require_once("includes/header.php"); ?>
  18.  
  19. <?php
  20.     if ( isset($_GET["logout"]) )
  21.     {
  22.         if ( $_GET["logout"] == 1  ) $message = "Successfully logged out" ;
  23.     }
  24.    
  25.     if (logged_in())
  26.     {
  27.     //    redirect_to("index.php?loggedin=1") ;
  28.     }
  29.     if ( isset($_POST["submit"]) )
  30.     {
  31.         $errors = array() ;
  32.        // echo "this shouldn't be here" ;
  33.         // validating if username is empty. do the same for password.
  34.         if ( !isset($_POST["email"]))
  35.          {
  36.             $errors[] = $_POST["email"] ;
  37.         }  
  38.         if ( !isset($_POST["password"]))
  39.          {
  40.             $errors[] = $_POST["password"] ;
  41.         }    
  42.  
  43.         //if after validating everything is all right.
  44.         if (empty($errors))
  45.         {
  46.            
  47.             $email = $_POST["email"]  ;
  48.             $hashed_password = sha1($_POST["password"] ) ;
  49.            
  50.             $query = " SELECT * FROM users
  51.                        WHERE email = '{$email}'
  52.                         AND hashed_password = '{$hashed_password}'
  53.                        " ;
  54.            
  55.             $result_set = mysql_query($query, $connection) ;
  56.             confirm_query($result_set) ;
  57.            
  58.             // Various methods to check if the query went smoothly.
  59.              if(mysql_num_rows($result_set) == 1 )  //first method
  60.             {
  61.                 $message = " - success! " ;
  62.                 $found_user = mysql_fetch_array($result_set) ;
  63.                 // $_COOKIE["user_id"] = $found_user["id"] ; doesn't works don't know why.
  64.                // setcookie("user_id", $found_user["id"])  ; // works !!
  65.                
  66.                 $_SESSION['user_id'] = $found_user["id"] ;
  67.                 $_SESSION['email'] = $found_user["email"] ;
  68.                 $_SESSION['colony_id'] = $found_user["colony_id"] ;
  69.                
  70.                // this needs to be on top of the page.
  71.                /* if ( $_POST["remember"] == "on")
  72.                 {
  73.                    $message .= " - remember me  - " ;
  74.                    // extend expiration date of cookie
  75.                    session_set_cookie_params('3600');
  76.                 } */
  77.               //  redirect_to("index.php") ;
  78.             }
  79.             else
  80.             {
  81.                 $message = " - no success. Problem? " . mysql_error() ;
  82.             }
  83.         }
  84.         else
  85.         {
  86.             $message .= " - You forgot to enter your username/password" ;
  87.         }
  88.  
  89.     }
  90. ?>
  91.  
  92.  
  93. <div id="content-wrap">    
  94.     <div id="main">
  95.         <a name="TemplateInfo" id="TemplateInfo"></a>
  96.         <?php if ( isset($message) ) echo "<h2>{$message}</h2>"  ?>
  97.         <h1>Login <span class="green">to delhibuy.in</span></h1>
  98.         <hr/>
  99.         <?php  if (isset($message)) { echo $message ; } ?>
  100.         <p><strong>Log in </strong> to access your account settings.</p>
  101.         <form action="login.php" method="post" >
  102.             <p>
  103.                 <label>Email</label>
  104.                 <input type="text" name="email" />
  105.                 <label>Password</label>
  106.                 <input type="password" name="password" />
  107.                 <br/>
  108.                 <input type="checkbox" name="remember" id="remember" value="on" /> Save Password <br/>                
  109.                 <input class="button" type="submit" name="submit" value="Submit" />
  110.             </p>
  111.         </form>
  112.     </div>
  113. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement