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> 
5
  • 3
    Danger: You are using an obsolete database API and should use a modern replacement. You are also vulnerable to SQL injection attacks that a modern API would make it easier to defend yourself from. Commented Dec 16, 2014 at 7:23
  • 1
    Danger: You are using an unsuitable hashing algorithm and need to take better care of your users' passwords. Commented Dec 16, 2014 at 7: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. Commented Dec 16, 2014 at 7:24
  • yes .its my friend comment. i need to know how to use cookies properly . Commented Dec 16, 2014 at 7:25
  • That isn't what you asked though. Even if it was, Stackoverflow is for specific programming problems, not introductory cookie tutorials. Commented Dec 16, 2014 at 7:26

1 Answer 1

-2

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); } ?> 
Sign up to request clarification or add additional context in comments.

10 Comments

do i need to create new page or just put the codes in if(count ==1)?
No you donot need to create a new pages just put the code after if(count ==1)
This code should never be used in production. This will result in the user's password being stored on their system in plaintext.
please oh please, I beg you not to go with this solution. Read this: stackoverflow.com/questions/549/…
never put password into a cookie
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.