New Zenner
- Join Date:
- Feb 2007
- Location:
- Vienna
- Posts:
- 38
- Plugin Contributions:
- 0
Is a Permanent Login (Auto-Login) Possible?
hey,
how could it be possible to let users "stay logged in on this computer" (auto / permanent login)?
thx
Views: 54,339
New Zenner
hey,
how could it be possible to let users "stay logged in on this computer" (auto / permanent login)?
thx
Totally Zenned
Sure, you just need to set a cookie, and configure the Zen Cart login to look for it.
http://us2.php.net/manual/en/features.cookies.php
Then take a look at...- [STORE_ROOT]/includes/modules/pages/login/header.php
New Zenner
okay, that works really nice.
but since it's so easy to modify cookies, how to make it safe?
store the password as md5-string in the cookie?
Totally Zenned
The cookie should definitely have the PW encoded.
New Zenner
sorry, but WHY wouldn't you take md5-encryption for the customers password?
zen_validate_password doesn't help any, because that function deals with the unencrypted password as value.
in the cookie i have an md5... and the function zen_encrypt_password always produces a different string...
how would you suggest to compare the md5-pw to the one in the db?
New Zenner
sorry, my mistake.
of course i can store the password from the db in the cookie and have not to deal with this extendet encryption method :P
Totally Zenned
Is this explained (i.e. a step-by-step how-to with code examples) anywhere for people like me - non-programmers but willing to have ago?
Totally Zenned
I'll rephrase that - does anyone have a step-by-step guide as how to incorporate this in ZC? Or better still, a contribution? :wink2:
New Zenner
okay, i'll write a brief explanation of that.
but tomorrow... :P
New Zenner
hi.1. first of all, add a checkbox to your login-form called something like "permLogin".
2. **edit the file "/includes/modules/pages/login/header_php.php"
**if the login is ok, zencart will proceed to the beyond line 57 and does all the stuff around line 70. just after this we hook in. put that code there:
_ $c_str = implode("~~~", $c);
_ setcookie("zencart_cookie_permlogin", $c_str, time()+36000000);
}
*
this will store all the relevant information in the cookie.
3. **edit the file "/includes/modules/pages/index/header_php.php"
**if you start your zencart, this page will be loaded. here we check if the login is set and if, then we login automatically.
at the very top of that file, just after "$zco_notifier..." add this code:
_
$q = "SELECT customers_password FROM " . TABLE_CUSTOMERS . " WHERE customers_id=" . $c[0];
$r = $db->Execute($q);
$pw_cookie = zen_db_prepare_input($c[7]);
$pw_zencart = $r->fields['customers_password'];
if ($pw_cookie == $pw_zencart) {
_ $SESSION['customer_id'] = $c[0];
** $SESSION['customer_default_address_id'] = $c[1];
** $SESSION['customers_authorization'] = $c[2];
** $SESSION['customer_first_name'] = $c[3];
** $SESSION['customer_last_name'] = $c[4];
** $SESSION['customer_country_id'] = $c[5];
** $SESSION['customer_zone_id'] = $c[6];
** $SESSION['cart']->restore_contents();
** }
** }
}
*_
_
Thats pretty much it
:smile:
Totally Zenned
Thankyou - much appreciated.
New Zenner
Ok, I have done a few searches, but I couldn't find anything definitive.
add a checkbox to your login-form called something like "permLogin".
How would I go about adding a checkbox. From your instructions I can definately do the rest, but the checkbox stumps me.
Oh and thank you very much for the instructions, I love that my customers can be logged in all of the time.
Pat
New Zenner
hey, no problem!
it's a template file you should first copy into your own template-directory.
Totally Zenned
Good stuff, crazy_chris. :thumbsup:
New Zenner
Hi crazy_chris, I just wanted to stop by and thank you for this.
I haven't got it working yet, (I got the tick box and the cookie imbeds it'self, but it does not log me back in again) but I will play around with it and I am sure I will be able to figure it out. It is likely I just put the code in the wrong spot, so I will look at the logic of the statements.
Again, thanks
Pat
Totally Zenned
Hmm - I get this error ```
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
in:
[SELECT customers_password FROM zen_customers WHERE customers_id=]
And the code I have copied and pasted from above and placed exactly where recommended in includes/modules/pages/login/header_php.php is```
if (substr_count($_COOKIE["zencart_cookie_permlogin"], "~~~") > 1) {
if (empty($_SESSION['customer_id'])) {
$c = explode("~~~", $_COOKIE["zencart_cookie_permlogin"]);
$q = "SELECT customers_password FROM " . TABLE_CUSTOMERS . " WHERE customers_id=" . $c[0];
$r = $db->Execute($q);
$pw_cookie = zen_db_prepare_input($c[7]);
$pw_zencart = $r->fields['customers_password'];
if ($pw_cookie == $pw_zencart) {
$_SESSION['customer_id'] = $c[0];
$_SESSION['customer_default_address_id'] = $c[1];
$_SESSION['customers_authorization'] = $c[2];
$_SESSION['customer_first_name'] = $c[3];
$_SESSION['customer_last_name'] = $c[4];
$_SESSION['customer_country_id'] = $c[5];
$_SESSION['customer_zone_id'] = $c[6];
$_SESSION['cart']->restore_contents();
}
}
}
I'm no expert, but there doesn't seem to be anything wrong with that. And I've checked in the db that the required data is present. :unsure:
New Zenner
hey, is this a joke... because you just put the lines in the wrong file!! :blush:
the code you just posted (for automatically logging in) is meant to be put in **"/includes/modules/pages/index/header_php.php"
**the file "includes/modules/pages/login/header_php.php" (where you put the mentioned code) is for the original login-process where you set the cookie for the permanent login.
:P if you experience any troubles, post again!
Totally Zenned
Damn - my human side is showing again! :D
But actually, not as bas as it seemed...I HAD put it in the right place - I had just pasted the wrong filename in that previous post.
New Zenner
hehe, alright then :P
well, it seems, it doesn't find the customer_id in the cookie.
could you please add this code before the "$c = explode(....)":
"echo $_COOKIE["zencart_cookie_permlogin"];"
and post the output here?
Totally Zenned
Will do . but while I'm doing that, could you be a bit more specific about > does all the stuff around line 70. just after this we hook in. put that code there
Should it be at about line 72 after $check_country or about line 80 after the $_SESSION lines?
This one is in login/header_php.php
Fields marked required must be completed.
Tell staff why this post should be reviewed.
Required for login, security, and core site functionality.
Help us understand how the site is used so we can improve it.
Used for promotion and personalized campaign measurement.