7

I was making a login page. so I already can login into another page. then in my login page I need to put remember me checkbox and PHP. so which part in this codes that I need to put my "remember me " codes ? please help me.

this is login1.php

<?php
session_start();
//database connection
$servername     = "localhost";
$username       = "root";
$password       = "";
$dbname         = "lala";

// Create connection
$link = mysql_connect($servername,$username,$password) or die("Could not connect");

$db= mysql_select_db("$dbname",$link) or die ("Could not select database");

$login = $_POST['login'];
$password = md5($_POST['password']);
$rememberme = $_POST['remember_me'];

$result = mysql_query("SELECT * from admin WHERE working_id = '$login' and password = '$password'");
$count = mysql_num_rows($result);

if($count==1)
{
    //check remember me is on or off
    //if off then session login
    //else add cookie

    $_SESSION['username'] = $login;
    $_SESSION['password'] = $password;

    $result1 = mysql_query("SELECT * from admin WHERE working_id = '$login' and password = '$password'");
    while($row = mysql_fetch_array($result1)){
        $_SESSION['gp'] = $row['gpType'];
    }
    header('Location:dashboard.php');
}
else 
{
    $_SESSION['username'] = NULL;
    $_SESSION['password'] = NULL;

    ?>
    <script type = "text/Javascript">
    alert("Sorry , wrong username or password");
    setTimeout("location.href = 'abc.php';");
    </script>
    <?php
}
?>

this is my html

    <p><input type="password" name="password" value="" placeholder="Password"></p>
    </div>
     <div id="form2">

    <p class="remember_me">
      <label>

        <input type="checkbox" name="remember_me" id="remember_me">
        Remember me 
      </label>
    </p></div>
    <div id="form3">
    <p class="submit"><input type="submit" name="commit" value="Login"></p>
  </form>
  </div>
Grant
  • 2,413
  • 2
  • 30
  • 41
ace
  • 73
  • 1
  • 1
  • 4
  • 3
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/quessations/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Dec 16 '14 at 07:23
  • 1
    **Danger**: You are using [an unsuitable hashing algorithm](http://php.net/manual/en/faq.passwords.php) and need to [take better care](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) of your users' passwords. – Quentin Dec 16 '14 at 07:23
  • "which part in this codes that i need to put my "remember me " codes" — Err… that would be the bit where you have written a comment telling you where to put them. – Quentin Dec 16 '14 at 07:24
  • yes .its my friend comment. i need to know how to use cookies properly . – ace Dec 16 '14 at 07:25
  • That isn't what you asked though. Even if it was, Stackoverflow is for specific programming problems, not [introductory cookie tutorials](https://duckduckgo.com/?q=pho+cookie+tutorial). – Quentin Dec 16 '14 at 07:26

1 Answers1

0

Just Use this code after getting the $login and $password

<?php   
if($_POST["remember_me"]=='1' || $_POST["remember_me"]=='on')
                    {
                    $hour = time() + 3600 * 24 * 30;
                    setcookie('username', $login, $hour);
                         setcookie('password', $password, $hour);
                    }
?>
khan Asim
  • 349
  • 1
  • 3
  • 13