Link to home
Start Free TrialLog in
Avatar of lhaluska
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>');
}
?>
Avatar of ncoo
ncoo

A cookie is just a cookie, like HTML is HTML it don't matter how it was made, it always is the same (if valid).


$cookie = $_COOKIE['value'];
<?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>');
}
?>
ASKER CERTIFIED SOLUTION
Avatar of ncoo
ncoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lhaluska

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\ServiceRequest\admin\test.php on line 2
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
}
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.
I added the expired = never. It still doesn't work.
Do this tell me what you get.
<?php
print_r($_COOKIE);
?>
Array ( [EMAIL] => lhaluska@cup.com [PHONE] => +1 708 225 1996 [STAFFDEPT] => 5996 [STAFFID] => LHaluska [ASPSESSIONIDACDBDDSC] => FPMLDDHCEJOFPMHFGGMAAOPC [CFID] => 34325 [CFMAGIC] => 34325:80010565 [CFTOKEN] => 80010565 )