Jump to content

remember me


squiblo

Recommended Posts

this is my form to login

<form name="form1" method="post" action="checklogin.php">
   <input type="text" id="myusername" style="position:absolute;left:651px;top:59px;width:174px;font-family:Arial;font-size:13px;z-index:4" size="29" name="myusername" value="" title="username">
   <input type="password" id="mypassword" style="position:absolute;left:651px;top:86px;width:174px;font-family:Arial;font-size:13px;z-index:5" size="29" name="mypassword" value="" tabindex="password" title="password">
   <input type="checkbox" id="Checkbox1" name="Checkbox1" value="on" style="position:absolute;left:648px;top:113px;font-family:Arial;font-size:13px;z-index:6">
   <input type="submit" id="Button1" name="Login" value="Login" style="position:absolute;left:778px;top:117px;width:50px;height:43px;font-family:Arial;font-size:13px;z-index:8" title="Login">
</form>

 

but i don't actually know how to get the "remember me" to work or where to put the script.

Link to comment
Share on other sites

Do i put this code on the page where you login or the profile page when logged in??

 

void session_set_cookie_params  ( int $lifetime  [, string $path  [, string $domain  [, bool $secure= false  [, bool $httponly= false  ]]]] )

Link to comment
Share on other sites

Do i put this code on the page where you login or the profile page when logged in??

 

void session_set_cookie_params  ( int $lifetime  [, string $path  [, string $domain  [, bool $secure= false  [, bool $httponly= false  ]]]] )

 

you need to call session_set_cookie_params() for every request and before session_start() is called.
Link to comment
Share on other sites

you can put a check box in the login, and then check it in login.php code whether its checked or not. If yes then save the details of the user for next time by using cookies on his/her pc.

 

Please elaborate to which information you are referring?

 

A session cookie has by default a lifetime of 0 (which means it is destroyed upon browser closier). If you modify the lifetime of the session cookie then the session on your server won't expire until the client-side cookie does or until you destroy the session or the browser crumbles the cookie.

Link to comment
Share on other sites

login.php

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['Login'])){
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
session_register("myusername");
session_register("mypassword"); 
header("location:profile.php");
}
else {
header("");
}
}
?>

 

 

profile.php

<?php
session_start();
if(!$_SESSION['myusername']){
header("location:index.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>

 

login form

<form name="form1" method="post" action="login.php">
   <input type="text" id="myusername" style="position:absolute;left:651px;top:59px;width:174px;font-family:Arial;font-size:13px;z-index:4" size="29" name="myusername" value="" title="username">
   <input type="password" id="mypassword" style="position:absolute;left:651px;top:86px;width:174px;font-family:Arial;font-size:13px;z-index:5" size="29" name="mypassword" value="" tabindex="password" title="password">
   <input type="checkbox" id="Checkbox1" name="Checkbox1" value="on" style="position:absolute;left:648px;top:113px;font-family:Arial;font-size:13px;z-index:6">
   <input type="submit" id="Button1" name="Login" value="Login" style="position:absolute;left:778px;top:117px;width:50px;height:43px;font-family:Arial;font-size:13px;z-index:8" title="Login">
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.