Hello,
I was wondering if anyone could help me figure out why my coding is not setting the cookie
as it should. I've checked write permission issues, and that doesnt seem to be it. Its not even
trying to place the cookie and failing, just not writing it at all. As this is for a shopping cart
program, it is slightly essential to have the cookie set for anyone to add items to their cart.
Below is the code portions that deal with session creation and cookie set/get.
Thanks
TimmyC
//CCGetCookie @0-705AF8CB
function CCGetCookie($parameter_name)
{
global $HTTP_COOKIE_VARS;
return isset($HTTP_COOKIE_VARS[$parameter_name]) ? $HTTP_COOKIE_VARS[$parameter_name] : "";
}
//End CCGetCookie
//CCSetCookie @0-1E0B074A
function CCSetCookie($parameter_name, $param_value)
{
setcookie ($parameter_name, $param_value, time() + 3600 * 24 * 366);
}
//End CCSetCookie
//CCGetSession @0-9BBC6D71
function CCGetSession($parameter_name)
{
global $HTTP_SESSION_VARS;
return isset($HTTP_SESSION_VARS[$parameter_name]) ? $HTTP_SESSION_VARS[$parameter_name] : "";
}
//End CCGetSession
//CCSetSession @0-0F088E96
function CCSetSession($param_name, $param_value)
{
global $HTTP_SESSION_VARS;
global ${$param_name};
if(session_is_registered($param_name))
session_unregister($param_name);
${$param_name} = $param_value;
session_register($param_name);
$HTTP_SESSION_VARS[$param_name] = $param_value;
}
//End CCSetSession
Thanks for your help with this,
TimmyC
Cookie Problem?
Started by TimmyC, Feb 07 2007 12:50 PM
3 replies to this topic
#1
Posted 07 February 2007 - 12:50 PM
#2
Posted 07 February 2007 - 01:01 PM
I'll just tell you now that you are using depreciated functions. Instead of using session_register() and session_unregister(), and using the $HTTP_COOKIE_VARS and $HTTP_SESSION_VARS superglobals, you should use the $_SESSION and $_COOKIE superglobals.
Also since they are superglobals you don't need to declare them global inside each function.
Have you checked your browser for the cookie? Does your browser accept cookies? Otherwise you may be using the set_cookie() function wrong. It should look like this for it to work in what I've tried with my experience.
This sets the cookie domain to your site's root, so it will actually set correctly for your domain.
And simply use the $_COOKIE superglobal to retrieve info.
And with sessions the same.
Also since they are superglobals you don't need to declare them global inside each function.
Have you checked your browser for the cookie? Does your browser accept cookies? Otherwise you may be using the set_cookie() function wrong. It should look like this for it to work in what I've tried with my experience.
setcookie($parameter_name, $param_value, time() + 3600 * 24 * 366, '/');
This sets the cookie domain to your site's root, so it will actually set correctly for your domain.
And simply use the $_COOKIE superglobal to retrieve info.
function CCGetCookie($parameter_name){
return isset($_COOKIE[$parameter_name]) ? $_COOKIE[$parameter_name] : '';
}
And with sessions the same.
function CCGetSession($parameter_name){
return isset($_SESSION[$parameter_name]) ? $_SESSION[$parameter_name] : '';
}
function CCSetSession($param_name, $param_value){
global ${$param_name};
${$param_name} = $param_value;
$_SESSION[$param_name] = $param_value;
}
#3
Posted 08 February 2007 - 11:44 AM
Thanks for the reply, i'll try what you've suggested and see if I have any better results.
And as for cookie check, I've set the browser to ask for all cookies, and I dont even get asked. Nor do I find the cookie anywhere else on my system. (Someone had suggested maybe it was being placed in the wrong location).
Thanks again,
TimmyC
And as for cookie check, I've set the browser to ask for all cookies, and I dont even get asked. Nor do I find the cookie anywhere else on my system. (Someone had suggested maybe it was being placed in the wrong location).
Thanks again,
TimmyC
#4
Posted 09 February 2007 - 01:55 PM
I had a similar problem which was not due to the browser blocking the cookies but because of an anti-virus program I had running. If demon's suggestions don't work try quickly disabling any anti-virus programs you have running (if you use any).
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
