We help IT Professionals succeed at work.

Read a coldfusion cookie with php?

lhaluska
lhaluska asked
on
Medium Priority
491 Views
Last Modified: 2013-12-20
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>');
}
?>
Comment
Watch Question

Commented:
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'];

Commented:
<?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>');
}
?>
Commented:
On second thought:

<?php
if ($_COOKIE['staffID']==null) {
   die('<font size="+3">Your cookie has expired, please login again by clicking <a href="../login.cfm">here</a>.</font>');
}
?>

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
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

Commented:
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
}
Brijesh ChauhanStaff IT Engineer

Commented:
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.

Author

Commented:
I added the expired = never. It still doesn't work.

Commented:
Do this tell me what you get.
<?php
print_r($_COOKIE);
?>

Author

Commented:
Array ( [EMAIL] => lhaluska@cup.com [PHONE] => +1 708 225 1996 [STAFFDEPT] => 5996 [STAFFID] => LHaluska [ASPSESSIONIDACDBDDSC] => FPMLDDHCEJOFPMHFGGMAAOPC [CFID] => 34325 [CFMAGIC] => 34325:80010565 [CFTOKEN] => 80010565 )
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.