Skip navigation
Currently Being Moderated

cookies by cfm may retrieved by php

Nov 24, 2010 3:28 PM

cookies by cfm may retrieved by php? if iframe have or not (other page)?

In a cfm page may insert:

 

<iframe src="country.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" width="0" height="0" style=" border:none"></iframe>

 

where country.php:                 // to get ip I used $_COOKIE['countNumVisitor'] set by cfm, get by php,  well seems default NULL appear in country always, where error?

 

 

<?php

function getIP()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
else $ip = “UNKNOWN”;
return $ip;
}

$ipNEW = getIP();
$IP=$ipNEW;
if ((!empty($IP)) && ($IP != "UNKNOWN")){
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$IP);
} else
$country = 'unknown';

    include("pass/passwords.php");

$linkid = mysql_connect($hostname,$username,$password);
@mysql_select_db($database,$linkid) or die( "Unable to select database");
$countNumVisitor=$_COOKIE['countNumVisitor']);
$query15 = "INSERT INTO yyyy SET country='$country' WHERE countNumVisitor = $countNumVisitor";    // refURL
$result15 = @mysql_query($query15,$linkid) or die("Unable to execute query. Please try again later. line 168");  // linkid2


mysql_close($linkid);
?>

 
Replies
  • Currently Being Moderated
    Nov 24, 2010 11:52 PM   in reply to 123polis123

    Don't see why not, cookies are based on a domain, not a technology.

     

    Try creating a simple cookie using CFCOOKIE then try reading it in with PHP in the way you normally would, I don't see why it wouldn't work. Bear in mind if you're using doing the write and read on the same page that I'm not sure at what point CF would write the cookie, whether it's as the page *begins* to render or finishes rendering.

     

    Therefore the cookie may not be immediately apparent, but should be easy enough to test.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2010 1:18 AM   in reply to 123polis123

    The contents of an iframe are a separate request to the request for the "main" window.  Frames and that sort of thing are a browser conceit: neither the web server nor CF have any idea how the requests will be handled on the browser, they just see two requests.  Both of which are handled like any other requests would be.  They have no relation to one another.

     

    Why don't you just TRY IT and see if it works?  It'll only take 5min to knock together a test...

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2010 2:19 AM   in reply to 123polis123

    Like I said: as far as the servers are concerned (web server, CF & PHP servers), they are not "the same page".  Servers don't think in "pages" they think in "requests".  When a browser requests a web page which in turn has an iframe in it, that's two separate requests: one for the main page, one for the iframe.  They only look like "the same page" because that's how the browser chooses to render them.  On the server end of things they are two distinct & unrelated requests.

     

    You might need to look at casing issues in regards to the cookie key names.  CF always capitalises them, I think, whereas PHP is case-sensitive.

     

    You should probably use an HTTP sniffer to watch what cookie data is being moved too/from the browser/servers for each request.  That will probably shed some light on the scene...

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 28, 2010 12:15 PM   in reply to Owain North

    Owainnorth wrote:

     

    Don't see why not, cookies are based on a domain, not a technology.

     

    Cookies may in fact depend on the technology. For example, I don't expect PHP to be able to make anything of Coldfusion's CFID and CFToken cookies.

     
    |
    Mark as:
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Nov 28, 2010 7:25 PM   in reply to BKBK

    It may not be able to match the values of CFID and CFTOKEN to meaningful internal values, but it can certainly read the values if both applications are within the same domain scope. In situations like this, it's fairly common to write a "cookie cracker" - a script which can accept tokens like these and return a user identity. So, you could write a CF program to crack these cookies, then invoke that from your PHP program which received the cookies.

     

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

     

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

     

    Read this before you post:

    http://forums.adobe.com/thread/607238

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 28, 2010 11:28 PM   in reply to Dave Watts

    Well yes quite, what the man with the signature said. I never said that PHP would be able to understand a CFID, simply that it could read it, which it can. If you want any kind of communication between PHP and CF I'd assumed you'd not be trying to use the built-in methods for authentication.

     
    |
    Mark as:
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Dec 4, 2010 3:55 PM   in reply to 123polis123

    Are your CF and PHP applications running within the same host? If not, they won't be able to share cookies unless they're within the same domain and you specify a domain-wide cookie using the DOMAIN attribute of CFCOOKIE.

     

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

     

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

     

    Read this before you post:

    http://forums.adobe.com/thread/607238

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 5, 2010 7:55 AM   in reply to 123polis123

    Right, it's as simple as expected. Two pages:

     

    /index.php:

    <?php
    echo($_COOKIE['TESTVAR']) ;
    ?>

     

    /index.cfm:

    <cfcookie domain="mydomain.co.uk" name="testvar" value="Yee-hah!" />
    <iframe src="/test.php">
    </iframe>

     

    Result when index.cfm is called? PHP outputs the value of the cookie as expected. Where's the issue? Or have I missed something?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 5, 2010 8:04 AM   in reply to 123polis123

    I'm not sure, why don't you try it and see?

     
    |
    Mark as:
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Dec 5, 2010 10:09 AM   in reply to 123polis123

    Only if the CF and PHP applications are on different hosts within the same domain. By default, cookies created with CFCOOKIE are host-specific.

     

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

     

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

     

    Read this before you post:

    http://forums.adobe.com/thread/607238

     
    |
    Mark as:
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Dec 6, 2010 1:43 PM   in reply to 123polis123

    If you just use this:

     

    <cfcookie name="foo" value="bar">

     

    the cookie will be available for every page on that host.

     

    If you use a DOMAIN attribute, the cookie will be available for every page within that domain.

     

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

     

    Read this before you post:

    http://forums.adobe.com/thread/607238

     
    |
    Mark as:
  • Dave Watts
    747 posts
    Mar 11, 2003
    Currently Being Moderated
    Dec 6, 2010 2:17 PM   in reply to 123polis123

    That's not valid syntax for the DOMAIN attribute. If you wanted to ensure that cookies would be sent to www.figleaf.com and training.figleaf.com, you'd use this:

     

    <cfcookie domain=".figleaf.com" ...>

     

    As for a CF/PHP example, I can't do that right now, as the computer I'm using doesn't have either installed. But I may have time tonight to do this.

     

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

     

    Read this before you post:

    http://forums.adobe.com/thread/607238

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 7, 2010 12:21 AM   in reply to 123polis123

    > can you send a simple working snipet cfml/php using iframe that works?

     

    What's wrong with the completely working example I've already posted up for you?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 7, 2010 1:10 AM   in reply to 123polis123

    In your PHP doc, change:

     

      echo($_COOKIE['countNumVisitor']);

     

    To:

     

      echo($_COOKIE['COUNTNUMVISITOR']);

     

    Dunno about yours, but mine seems to insist on an upper case cookie name.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 7, 2010 3:10 AM   in reply to 123polis123

    I think you might find yourself on your own from here on in, as this is a ColdFusion forum not a PHP one. I only know the absolute basics of PHP - someone might be able to help you further but it has been proven that this works.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points