Cookie Keys
Moderator: General Moderators
Cookie Keys
I'm an ASP developer by trade and am not familiar with the nuances of PHP and am struggling with turning a cookie value into a session var in PHP.
I've got a cookie set using keys in ASP:
Response.Cookies ("SUPPORTFORUM")("SLUserGUID") = Session("SL_UserGUID")
Response.Cookies ("SUPPORTFORUM")("SLUserNAME") = Session("SL_Username")
I need to write this cookie to a session var on a PHP page, problem is i can work out the syntax to call the cookie as it uses key pairs, in asp, it'd be simply
session("blahblah") = Request.Cookies ("SUPPORTFORUM")("SLUserNAME")
But in PHP i'm trying stuff like:
$_SESSION['SL_Username'] = $_COOKIE[$SL_UserNAME];
or
$_SESSION['SL_Username'] = $_COOKIE[$SLUserGUID][$SL_UserNAME];
but obviously it wont work as the SL_UserNAME value is stored within the cookies SUPPORTFORUM key.
Anyone know how to do this?
Thanks
I've got a cookie set using keys in ASP:
Response.Cookies ("SUPPORTFORUM")("SLUserGUID") = Session("SL_UserGUID")
Response.Cookies ("SUPPORTFORUM")("SLUserNAME") = Session("SL_Username")
I need to write this cookie to a session var on a PHP page, problem is i can work out the syntax to call the cookie as it uses key pairs, in asp, it'd be simply
session("blahblah") = Request.Cookies ("SUPPORTFORUM")("SLUserNAME")
But in PHP i'm trying stuff like:
$_SESSION['SL_Username'] = $_COOKIE[$SL_UserNAME];
or
$_SESSION['SL_Username'] = $_COOKIE[$SLUserGUID][$SL_UserNAME];
but obviously it wont work as the SL_UserNAME value is stored within the cookies SUPPORTFORUM key.
Anyone know how to do this?
Thanks
Should that be :p
Code: Select all
print_r($_COOKIE);That gives me:
Array ( [SUPPORTFORUM] => SLUserID=28&LastLogin=9/30/2005 5:53:01 AM&SLUserNAME=someuser&SLUserGUID=D4FEE5564ADC34870EE8406CB473D [ASPSESSIONIDQSRSACAQ] => EKBPKGGBFFFPALICFACGAAM [360Forum_data] => a:0:{} [360Forum_sid] => af9b65f46vvv0dc45e9dbe551bfcef81 [360Forum_t] => a:1:{i:2;i:1133689492;} )
So how do i load the SLUserNAME value into a session var called 'SL_Username'?
Ta
Array ( [SUPPORTFORUM] => SLUserID=28&LastLogin=9/30/2005 5:53:01 AM&SLUserNAME=someuser&SLUserGUID=D4FEE5564ADC34870EE8406CB473D [ASPSESSIONIDQSRSACAQ] => EKBPKGGBFFFPALICFACGAAM [360Forum_data] => a:0:{} [360Forum_sid] => af9b65f46vvv0dc45e9dbe551bfcef81 [360Forum_t] => a:1:{i:2;i:1133689492;} )
So how do i load the SLUserNAME value into a session var called 'SL_Username'?
Ta
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
Code: Select all
session_start():
$arr = explode('&', $_COOKIE['SUPPORTFORUM']);
$val = explode('=', $arr);
$_SESSION['SL_Username'] = $val[1];- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
nope, you didn't get it. he used it as a verb.Jenk wrote:Should that be:pCode: Select all
print_r($_COOKIE);
Yes, I got that thanks.n00b Saibot wrote:nope, you didn't get it. he used it as a verb.Jenk wrote:Should that be:pCode: Select all
print_r($_COOKIE);
But just incase durbs was to think that is how it is used, I decided to post what I did.
lol, i did use 'print_r() $_COOKIE' at first but a quick Googling put me right afetr it errored!
I've tried:
But the session var doesnt appear to be there (is echo the PHP equivalent of response.write?)
It also doesnt appear in the textbox on my page, basically its for a bit of PHPBB where i need to pre-fill the username textbox with a user name that was set in this cookie. The code is:
the code for setsitelockcookie.php is the code shown at the start of this post.
Cheers,
Durbs
I've tried:
Code: Select all
session_start():
$arr = explode('&', $_COOKIE['SUPPORTFORUM']);
$val = explode('=', $arr);
$_SESSION['SL_Username'] = $val[1];
Echo $_SESSION['SL_Username'];It also doesnt appear in the textbox on my page, basically its for a bit of PHPBB where i need to pre-fill the username textbox with a user name that was set in this cookie. The code is:
Code: Select all
include_once("setsitelockcookie.php");
if ($_SESSION['SL_Username'] == '')
{
$username = ($userdata['session_logged_in']) ? $userdata['username'] : '';
}
else
{
$username = $_SESSION['SL_Username'];
}Cheers,
Durbs
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
may like to use parse_str() since the cookie has a url encoded string in it..
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
I think you made an errorshiznatix wrote:that should workCode: Select all
session_start(): $arr = explode('&', $_COOKIE['SUPPORTFORUM']); $val = explode('=', $arr); $_SESSION['SL_Username'] = $val[1];
Code: Select all
<?php
session_start();
$arr = explode('&', $_COOKIE['SUPPORTFORUM']);
$val = explode('=', $arr[2]);
$_SESSION['SLUserNAME'] = $val[1];
?>But as feyd has suggested, parse_str() would be better (can you believe I forgot the name of that function? I have been search php.net for uritostr or uritoarr etc.. /me slaps forehead)