note 67863 added to function.setcookie
| From: | afallenhope at gmail dot com | Date: | Wed, 05 Jul 2006 22:44:24 +0000 |
| Subject: | note 67863 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114444@lists.php.net to get a copy of this message | ||
Hey,
I had a quick question to why my site wasn't retrieving cookies. I'm using an IFRAME that
sets the cookie and retrieves the cookie but ya it's not working here's what I have now,
if anyone could help me out it'd be greatly appreciated.
<?php
session_start();
// retrieve the submitted values
$username1 = $HTTP_POST_VARS["username"];
$password1 = $HTTP_POST_VARS["password"];
$rememberMe = $HTTP_POST_VARS["rememberMe"];
$username2 = $HTTP_COOKIE_VARS['afhUser'];
$password2 = $HTTP_COOKIE_VARS['afhPass'];
// make sure that rememberMe has a value
if ($rememberMe == "rememberMe"){
$rememberMe = "1";
}else{
$rememberMe = "0";
}
// let the config.php file connect to the database
include("config.php");
// check it the username exist
$query = "Select * from ".$DBprefix."signup where
username='$username1'";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)){
// check if his account is activated, if not skip to this if's else case
if ($row["actnum"] == "0"){
// and check if his account is not loccked, if not skip to this if's else case
if ($row["numloginfail"] <= 3){
// finally we check the database to see if the password is correct, if not skip to this if's
else case
if ($row["password"] == $password1){
// we determin the date for the lastlogin - field.
$datetime = date("d-m-Y G:i ");
// and we update that field
$query = "UPDATE ".$DBprefix."signup Set lastlogin = '$datetime' where
username='$username1'";
$result = mysql_query($query);
// now that the correct password is used to log-in, reset the numloginfail-field to 0
$query = "UPDATE ".$DBprefix."signup Set numloginfail = '0' where
username='$username1'";
$result = mysql_query($query);
// tell we want to work with sessions
// remove al the data from the session (auto logoff)
session_unset();
// remove the session itself
session_destroy();
// put the password in the session
@ session_register("pass");
$HTTP_SESSION_VARS["pass"] = $password1;
// put the username in the session
@ session_register("id");
$HTTP_SESSION_VARS["id"] = $username1;
// send the the cookie if needed
if($rememberMe=="1"){
$_COOKIE['afhUser'] = $username1;
$_COOKIE['afhPassENC'] = md5($username1);
$_COOKIE['afhPass'] = $password1;
setcookie("afhUser",$username1,(time()+604800));
setcookie("afhPassENC",md5($password1),(time()+604800));
setcookie("afhPass",$password1,(time()+604800));
}
// go to the secured page.
header("Location: members/index.php");
}
else{
// else the password is incorrect. Therofore we have to update the numloginfield and
lastloginfail field
----
Server IP: 66.207.199.35
Probable Submitter: 64.228.201.76
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.setcookie.php
Edit -- http://master.php.net/note/edit/67863
Del: integrated -- http://master.php.net/note/delete/67863/integrated
Del: useless -- http://master.php.net/note/delete/67863/useless
Del: bad code -- http://master.php.net/note/delete/67863/bad+code
Del: spam -- http://master.php.net/note/delete/67863/spam
Del: non-english -- http://master.php.net/note/delete/67863/non-english
Del: in docs -- http://master.php.net/note/delete/67863/in+docs
Del: other reasons-- http://master.php.net/note/delete/67863
Reject -- http://master.php.net/note/reject/67863
Search -- http://master.php.net/manage/user-notes.php