note 67863 rejected from function.setcookie by bjori
| From: | bjori@php.net | Date: | Thu, 06 Jul 2006 02:13:34 +0000 |
| Subject: | note 67863 rejected from function.setcookie by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114475@lists.php.net to get a copy of this message | ||
Note Submitter: afallenhope at gmail dot com
----
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