Skip to main content
Known Participant
November 24, 2010
Question

cookies by cfm may retrieved by php

  • November 24, 2010
  • 1 reply
  • 5826 views

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);
@6688122_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 = @6688122_query($query15,$linkid) or die("Unable to execute query. Please try again later. line 168");  // linkid2


mysql_close($linkid);
?>

    This topic has been closed for replies.

    1 reply

    Owainnorth
    Inspiring
    November 25, 2010

    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.

    Known Participant
    November 25, 2010

    what about iframe(of php page) inside cfm, is it correct?

    Inspiring
    November 25, 2010

    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