TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-12-2009, 02:08 PM   #1 (permalink)
xgd
The Visitor
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
xgd is on a distinguished road
Default How to add remember me feature ?

Hello,

I made this register/login script and all dya ive been trying to add a remember me feature but its not working out.

If someone is bothered to modify this script so it has a working remember me feature i would be grateful.

I have modified the login script that worked as follows (it still works for simply logging in but the user doesnt stay logged in if he checks the checkbox):

Code:
<?php

session_start();

if (isset($_POST['submit'])) {
    require_once('db_connect.php');
    if (empty($_POST['email'])) {
        echo "didnt enter EMAKL<br />";
    } else {
        $e = trim($_POST['email']);
    }

    if (empty($_POST['pass'])) {
        echo "Didnt enter PASS<br />";
    }
    else {
        $p = trim($_POST['pass']);

    }

    if ($e && $p) {
        $q = "SELECT user_id, first_name, user_level FROM users WHERE email='$e' AND pass=SHA1('$p')";
        $r = mysqli_query($dbc, $q) or trigger_error("Couldnt execute query 1");
        if (mysqli_num_rows($r) == 1) {
 
                  
            $_SESSION = mysqli_fetch_array($r);
			
			if(isset($_POST['remember'])) {
			
            setcookie("cookid", $_SESSION['user_id'], time()+60*60*24*100);
            setcookie("cookname", $_SESSION['first_name'], time()+60*60*24*100);
            setcookie("cooklevel", $_SESSION['user_level'], time()+60*60*24*100);
			
            header("Location: index.php");
			
            
        }
		}
        else {
            echo "Youre not in hte DB<br />";
        }
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <style type="text/css">
            <!--
            .style2 {color: #333333}
            .style3 {color: #ECE9D8}
            -->
        </style>
    </head>

    <body>
        <p><a href="register.php">Register</a> &nbsp;&nbsp;&nbsp;&nbsp;<a href="login.php">Login</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="password.php">Change Password</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="view_users.php">View Users</a> <a href="private.php">private</a></p>

        <h1>Login</h1>
        <form action="login.php" method="post">
            <input type="text" name="email" />
            <input type="text" name="pass" />
            <input type="submit" name="submit" value="Login" />
            <label>
                <input type="checkbox" name="remember" id="remember" />
                Remember me:</label>
        </form>


    </body>
</html>
Also this is the code i use to check if the user is logged in on my index.php page:

Code:
<?php
session_start();

if (isset($_SESSION['first_name'])) {
  
   echo "Hello man<br />";
   
   echo "<a href=\"logout.php\">logout</a>";
   
   }
   
   
   
   ?>
Please tell me if i should modify this also because of the remember me feature i want to add.

Thanks in advance
xgd is offline  
Reply With Quote
Old 07-12-2009, 02:28 PM   #2 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

use COOKIES
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 07-12-2009, 05:07 PM   #3 (permalink)
The Addict
 
adamdecaf's Avatar
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by webtuto View Post
use COOKIES
Which store a unique and dynamic id in them. Along with another cookie that stores a (known but random on a DB level) substring of the previous id's hash.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-12-2009, 07:28 PM   #4 (permalink)
xgd
The Visitor
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
xgd is on a distinguished road
Default

You mean use only cookies ?

I want to use sessions, but use cookies to make it permanent, how do i do that please ?
xgd is offline  
Reply With Quote
Old 07-12-2009, 07:31 PM   #5 (permalink)
The Addict
 
adamdecaf's Avatar
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by xgd View Post
You mean use only cookies ?

I want to use sessions, but use cookies to make it permanent, how do i do that please ?
Cookies do not have to be permanent, php.net has some great and trivial documentation on cookies.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SECURED REMEMBER ME Login praveenaj Advanced PHP Programming 1 02-12-2009 09:08 PM
Which PHP's feature made you crazy best? superthin Absolute Beginners 1 12-03-2008 01:08 PM
Feature suggestions Enfernikus The Lounge 1 11-15-2008 03:53 PM
Online Poll Feature for Website lashawnie General 2 05-09-2008 05:29 PM
new feature for registered members? Nor Feedback 6 12-06-2007 12:34 AM


All times are GMT. The time now is 01:35 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design