Advertisement

03.19.2008 at 10:43AM PDT, ID: 23254493
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.5

php mysql remember me login

Asked by Toube in PHP and Databases, PHP Scripting Language, MySQL Server

Hi, this is a follow up question for this question:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_21086125.html#a11746025

Heres how my login page looks like:

and below that is the index page that first should check for the cookie and the see if the user has timed out or is not logged in:

Now I have set the session timeout for 5 seconds just for testing it.. and now it totally ignores the cookie and logs me out after 5 seconds.. any clues?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
<?php
 
//login page
 
if (isset($_POST['submit']))
{
 
        $uname = ($_POST['uname']);
        $passwd = ($_POST['passwd']);
        $remember_me = ($_POST['remember_user']);
    // if form has been submitted
 
    /* check they filled in what they were supposed to and authenticate */
 
    $fd = fopen('/dev/urandom', 'r');
        $tmp = fread($fd, 1000);
        fclose($fd);
        $site_uhash = md5($tmp);
 
        if (isset($_POST['remember_user']))
        {
                $cookiedata = $_POST['uname']."|".md5($_POST['passwd'])."|".$site_uhash;
                setcookie("autologin", $cookiedata, time() + 31536000);
        }
 
        if(!$_POST['uname'])
        {
                        "";
        }
 
        else if(!$_POST['passwd'])
        {
                        "";
        }
 
    // authenticate.
 
    if (!get_magic_quotes_gpc())
    {
        $_POST['uname'] = addslashes($_POST['uname']);
    }
 
    $check = $db_object->query("SELECT users_id, username, password, userlevel, uhash, deluser_ FROM users WHERE username = '".$_POST['uname']."' AND deluser_ = '0'");
 
    if (MDB2::isError($check) || $check->numRows() == 0)
        {
                //echo ('<span style="font-weight: bold; color: #691717;">v&auml;&auml;r&auml; tunnus.</span>');
           //echo ('<br/>');
 
    }
        $sqlquery = "select * FROM users WHERE username = '".$_POST['uname']."' AND deluser_ = '0'";
        $result = mysql_query($sqlquery);
        while ($row = mysql_fetch_array($result))
        {
                $count_float = $row['count_float'];
                $float = $row['float_user'];
                $count = $row['count_logons'];
        }
 
    $info = $check->fetchRow();
    $count_add = $count+1;
 
    if ($float == 1)
    {
                $count_float_add = $count_float + 1;
        }
    // check passwords match
 
    $_POST['passwd'] = stripslashes($_POST['passwd']);
    $info['password'] = stripslashes($info['password']);
    $_POST['passwd'] = md5($_POST['passwd']);
 
    if ($_POST['passwd'] != $info['password'])
    {
       //echo ('<span style="font-weight: bold; color: #691717;">v&auml;&auml;r&auml; salasana.</span>');
        //echo ('<br/>');
        }
 
else
{
            // if we get here username and password are correct,
            //register session variables and set last login time.
 
            $date = date('d.m.Y H.i');
 
            // get userid from db query
            $usersid_ = $info['users_id'];
        $_SESSION['users_id'] = $usersid_;
 
            $update_login = $db_object->query("UPDATE users SET count_logons='$count_add', uhash='$site_uhash', count_float='$count_float_add' WHERE username = '".$_POST['uname']."'");
 
            $_POST['uname'] = stripslashes($_POST['uname']);
            $_SESSION['site_uhash'] = $site_uhash;
 
            $db_object->disconnect();
 
        $goback ="http://www.toubes-page.net/td/user";
        header ("Location: $goback");
}
 
}
?>
 
 
// Index.php page
 
<?php
 
require ('template.php');
include("db_connect.php");
include 'online_users/whosonlineupdate.php';
 
if (isset($_COOKIE['autologin']) && !isset($_SESSION['site_uhash']))
{
 
//this line checks that the cookie is set and the username session is not set (ie. the user has not yet been logged in and //they have the autologin cookie set).
 
 $splitcookie = explode("|",$_COOKIE['autologin']);
 $cookie_username = $splitcookie[0];
 $cookie_password = $splitcookie[1];
 $cookie_uhash = $splitcookie[2];
 
//the above code splits the data in the cookie so you have the user name in the first variable ($cookie_username) and the //password in the second ($cookie_password).
 
$query = "SELECT username, password, uhash FROM users WHERE username='$cookie_username' AND password='$cookie_password' AND uhash='$cookie_uhash' LIMIT 1;";
 
 $logincookie = mysql_query($query) or die(mysql_error());
 
 if (mysql_num_rows($logincookie) < 1)
 {
        echo "Cookie Error - Auto Login Failed!<br>\n";
 }
 
 // $users_id = mysql_result($logincookie, 0, "users_id");
  $site_uhash = mysql_result($logincookie, 0, "uhash");
  $_SESSION['site_uhash'] = $site_uhash;
  //$_SESSION['users_id'] = $users_id;
 
//In the above code you are using the results returned by the database to set the session vars up (like you would when you //handle the login normally), you may need to add some code here to set more data in sessions.
}
 
if ($logged_in == 0)
{
                $goback ="http://www.toubes-page.net/td/index.php?id=cpanel&page=logout&amp;logged_in=0";
                header ("Location: $goback");
}
 
if (!isset($_SESSION['count']))
{
    $_SESSION['count'] = 0;
    //$count = $_SESSION['count'];
    $_SESSION['session_start'] = time();
}
else
{
    $_SESSION['count']++;
}
$session_timeout = 5; // 1 hr (in sec)
 
$session_duration = time() - $_SESSION['session_start'];
if ($session_duration > $session_timeout)
{
    $goback ="http://www.toubes-page.net/td/index.php?id=cpanel&page=logout";
        header ("Location: $goback");
}
$_SESSION['session_start'] = time();
 
 
require ('basepage.php');
basepage("main");
?>
[+][-]03.19.2008 at 11:02AM PDT, ID: 21164060

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 11:13AM PDT, ID: 21164168

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 12:01PM PDT, ID: 21164663

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 12:45PM PDT, ID: 21165146

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 01:33PM PDT, ID: 21165593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 01:42PM PDT, ID: 21165697

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 02:03PM PDT, ID: 21165877

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 02:20PM PDT, ID: 21166032

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 02:39PM PDT, ID: 21166168

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 02:43PM PDT, ID: 21166205

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language, MySQL Server
Sign Up Now!
Solution Provided By: arnold
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.19.2008 at 11:44PM PDT, ID: 21168768

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 12:23AM PDT, ID: 21168875

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 01:37AM PDT, ID: 21169153

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628