Jump to content

Option to remember username and password


graham23s

Recommended Posts

Hi Guys,

 

when a user visits my site i was going to have a check box to save username and password, not sure how to go about this, i can make the check box fine but not sure what i would need exactly on the

 

login_check.php

 

<?php
     include("includes/db_connection.php");
     include("includes/constants.php");
     
 $username = trim(strtolower(mysql_real_escape_string($_POST['username'])));
 $password = trim(strtolower(mysql_real_escape_string($_POST['password'])));	

  	 if (empty($username) || empty($password)) {	
  	 
 echo "Please fill in both fields.";
 exit;	

 }	

 ## check the user is in the database ###############################################
 $login_query = "SELECT username,password FROM `membership` WHERE `username`='$username' AND `password`='$password'";
 $login_result = mysql_query($login_query) or die (mysql_error());

 $is_greater_than_1 = mysql_num_rows($login_result);

 // was there a user found?...#######################################################
 if($is_greater_than_1 != 1) {	

     echo "Sorry username and password combination not found.";
     exit;	
     
 } else {	

 ## User is logged in so Let's give him a cookie. ###################################
 setcookie ("member",$username,time()+1957240,"/"); 

 ## a variable to hold the cookie ###################################################
 $member = $username;

 ## If cookie failed set a session...################################################
 $_SESSION['member'] = 'member';	

 ## Update Login timer...############################################################
 $timer_query = "UPDATE `membership` SET `login`=now() WHERE `username`='$username' AND `password`='$password'";
 $timer_result = mysql_query($timer_query) or die (mysql_error());

     if ($timer_result) {	
     
 header("Location:my_account.php"); 

     } 
         
     } 
?>

 

form to remember this data, any advice would be great

 

cheers

 

Graham

Link to comment
Share on other sites

only way is to create a cookie, that doesnt expire, which i do beleive expires after teh browser is closed.  you may be able to selet time rembered for, and then set a cookie expire time for that, or simply make it sooooo far away into teh future, that the person will never expire..... In the file, simply go: if(isset($_COKIE['Set_User) || isset($_COOKIE['set_Pass'])) { etc.

 

 

gdlk

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.