How to put remember me (cookie) in PHP -
i making login page. can login page. in login page need put remember me checkbox , php. part in codes need put "remember me " codes ? please me.
this 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 * admin working_id = '$login' , password = '$password'"); $count = mysql_num_rows($result); if($count==1) { //check remember me on or off //if off session login //else add cookie $_session['username'] = $login; $_session['password'] = $password; $result1 = mysql_query("select * admin working_id = '$login' , 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 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>
just use code after getting $login , $password
<?php if($_post["remember_me"]=='1' || $_post["remember_me"]=='on') { $hour = time() + 3600 * 24 * 30; setcookie('username', $login, $hour); setcookie('password', $password, $hour); } ?>
Comments
Post a Comment