lhaluska
asked on
Read a coldfusion cookie with php?
Can php read a cookie writen in coldfusion? I have this code that is writen in coldfusion and needs to be translated to php but I want to read a cookie that was created from a coldfusion page made on the same server. Here is the code.
--------Coldfusion-------- -----
<cfif NOT IsDefined("COOKIE.staffID" )>
<cfoutput><font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</ a>.</font> </cfoutput >
<cfabort>
</cfif>
-----------PHP------------
<?php
if (! array_key_exists("staffID" ,$_COOKIE) ) {
die('<font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</ a>.</font> ');
}
?>
--------Coldfusion--------
<cfif NOT IsDefined("COOKIE.staffID"
<cfoutput><font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</
<cfabort>
</cfif>
-----------PHP------------
<?php
if (! array_key_exists("staffID"
die('<font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</
}
?>
<?php
if (!isset($_COOKIE['staffID' ])) {
die('<font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</ a>.</font> ');
}
?>
if (!isset($_COOKIE['staffID'
die('<font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am getting this output from that last post.If it works nothing should show up on the page right.Sorry I am a newbie.
Notice: Undefined index: staffID in C:\Inetpub\wwwroot\Service Request\ad min\test.p hp on line 2
Your cookie has expired, please login again by clicking here
Notice: Undefined index: staffID in C:\Inetpub\wwwroot\Service
Your cookie has expired, please login again by clicking here
if ($_COOKIE['staffID']==null )
{
//This will happen if the cookie does not exist or if the cookie contains no data
}
OR
if (!isset($_COOKIE['staffID' ]))
{
//This will happen if the cookie does not exist
}
{
//This will happen if the cookie does not exist or if the cookie contains no data
}
OR
if (!isset($_COOKIE['staffID'
{
//This will happen if the cookie does not exist
}
add to your coldfusion <cfcookie name="XXXX" expires="NEVER"> to ensure that your cookie variable does not expire, then you can access it using PHP.
ASKER
I added the expired = never. It still doesn't work.
Do this tell me what you get.
<?php
print_r($_COOKIE);
?>
<?php
print_r($_COOKIE);
?>
ASKER
Array ( [EMAIL] => lhaluska@cup.com [PHONE] => +1 708 225 1996 [STAFFDEPT] => 5996 [STAFFID] => LHaluska [ASPSESSIONIDACDBDDSC] => FPMLDDHCEJOFPMHFGGMAAOPC [CFID] => 34325 [CFMAGIC] => 34325:80010565 [CFTOKEN] => 80010565 )
$cookie = $_COOKIE['value'];