Jump to content

Can't get cookie value?


garethhall

Recommended Posts

Hi guys maybe you can help me out here. This it the first time I am using cookies and I can't seem to to get the the cookie value.

 

The odd thing is I can see the cookies when I check them through the browser they go a name and value.

 

I have 2 different scripts

1 the processLogin.php This is where you login

<?php
require_once("clientConn.php"); 
include("sharedFunctions.php");

session_start();  

//Set Variables
$loginName = checkVars($_POST['loginName']);
$password = checkVars(base64_encode($_POST['password']));
$time = time();
$remember = $_POST['remember'];
$msg = "";

if(isset($_POST['confirm']) && $_POST['loginName'] != "" && $_POST['password'] != ""){
$sql_mem = "SELECT * FROM members WHERE (memName = $loginName OR memEmailAddress = $loginName) AND memPassword = $password";
$rs_mem = mysql_query($sql_mem, $client);
$fnd_mem = mysql_num_rows($rs_mem);
$rw_mem = mysql_fetch_assoc($rs_mem);
if($fnd_mem){
	$_SESSION['kbsLogin'] = 1;
	if($remember){
		setcookie("kbsMemID",$rw_mem['memID'], $time + 3600*24*90);
		setcookie("kbsLoginName",$loginName, $time + 3600*24*90);
		setcookie("kbsPassword",$password, $time + 3600*24*90);	
	}
	header("Location: ../accountoverview.php");
	exit();
}else{
	header("Location: ../login.php?e=1");
	exit();
}		
}else{
header("Location: ../login.php?e=2");	
exit();
}

?>

 

and 2 sharedFunctions.php here I check to see if the member is logged in

 

<?php
//********************* initialize the session ***************************
if (!isset($_SESSION)) {
  session_start();
}

//************************ Protect Variables from SQL injection *****************************
function checkVars($value){
// Stripslashes
if (get_magic_quotes_gpc()){
 	$value = stripslashes($value);
}
// Quote if not a number
if (!is_numeric($value)){
	$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

//**************************************** User and session authentication **************************************************
function auth(){
echo $_COOKIE['kbsMemID'];
echo $_COOKIE['kbsLoginName'];
echo $_COOKIE['kbsPassword'];

if(isset($_COOKIE['kbsMemID']) && isset($_COOKIE['kbsLoginName']) && isset($_COOKIE['kbsPassword'])){
$memID = $_COOKIE['kbsMemID'];
$loginName = $_COOKIE['kbsLoginName'];
$pass = $_COOKIE['kbsPassword'];

$sql_mem = "SELECT * FROM members WHERE (memName = $loginName OR memEmailAddress = $loginName) AND memPassword = $password AND memID = $memID";
$rs_mem = mysql_query($sql_mem, $client);
$fnd_mem = mysql_num_rows($rs_mem);
$rw_mem = mysql_fetch_assoc($rs_mem);
if($fnd_mem){
	$_SESSION['kbsLogin'] = 1;
}else{
	echo "not logged in";
	exit();
}

}


}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.