?
Solved

Read a coldfusion cookie with php?

Posted on 2007-07-19
9
Medium Priority
?
438 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>');
}
?>
0
Comment
Question by:lhaluska
  • 5
  • 3
9 Comments
 
LVL 15

Expert Comment

by:ncoo
ID: 19526532
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'];
0
 
LVL 15

Expert Comment

by:ncoo
ID: 19526539
<?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>');
}
?>
0
 
LVL 15

Accepted Solution

by:
ncoo earned 2000 total points
ID: 19526548
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>');
}
?>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:lhaluska
ID: 19526586
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
0
 
LVL 15

Expert Comment

by:ncoo
ID: 19526635
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
}
0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 19528779
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.
0
 
LVL 1

Author Comment

by:lhaluska
ID: 19575947
I added the expired = never. It still doesn't work.
0
 
LVL 15

Expert Comment

by:ncoo
ID: 19578811
Do this tell me what you get.
<?php
print_r($_COOKIE);
?>
0
 
LVL 1

Author Comment

by:lhaluska
ID: 19578838
Array ( [EMAIL] => lhaluska@cup.com [PHONE] => +1 708 225 1996 [STAFFDEPT] => 5996 [STAFFID] => LHaluska [ASPSESSIONIDACDBDDSC] => FPMLDDHCEJOFPMHFGGMAAOPC [CFID] => 34325 [CFMAGIC] => 34325:80010565 [CFTOKEN] => 80010565 )
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question