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
https://forums.phpfreaks.com/topic/168577-cant-get-cookie-value/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.