Page 1 of 1
READ CFCOOKIE with PHP
Posted: Tue Jan 24, 2006 11:27 am
by webacadie
Is there a way to read a cookie made with CFCOOKIE in php?
I'd try
$user = $HTTP_COOKIE_VARS["webacadie"];
<?php print "our cookie says $user";?>
but I always have a blank like if my cookie is empty
If I try
<?php print_r($_COOKIE); ?>
The result is Array ( [WEBACADIE] => dskit )
and "dskit" is the value I'm trying to get
Any suggestion??
The fun of working on a system that's using CF and PHP is really something .... The website is all CF but client both a plugin that is made with PHP, I have to pass some value from CF to PHP and I can't do it via form .....
Posted: Tue Jan 24, 2006 11:36 am
by Chris Corbyn
$HTTP_COOKIE_VARS is deprecated.... use $_COOKIE[] instead
Code: Select all
if (!empty($_COOKIE['WEBACADIE']))
{
echo 'Cookie says '.$_COOKIE['WEBACADIE'];
}
Posted: Tue Jan 24, 2006 12:08 pm
by webacadie
Thanks a lot, it is working

Posted: Tue Jan 24, 2006 2:26 pm
by webacadie
Now if I want to put my cookie resutl in my query?
$sql = 'SELECT id, nom, client
FROM client
where datasource = $_COOKIE['WEBACADIE'];
or even
$conn->open('dswebacadie');
$user = $_COOKIE['WEBACADIE'];
$sql = 'SELECT id, nom, client
FROM client
where datasource = $user';
$rs = $conn->Execute($sql);
It doesn't work that way
Posted: Tue Jan 24, 2006 5:24 pm
by Chris Corbyn
You can't put variables in single quotes directly. PHP treats single quotes (string literal) as literal strings and so won't parse any variables inside them. If you use double quotes however PHP will parse variables.
It gets a bit confusing when you are referring to associative array values in double quotes strings though:
Quick demo....
Code: Select all
$foo = 'bar';
echo 'sheep say $foo'; //sheep say $foo
echo "sheep say $foo"; //sheep say bar
$foo = array();
$foo['bar'] = 'cheese';
echo "the moon is made of $foo['bar']"; //Gives error due to named key
echo "the moon is made of $foo[bar]"; //The moon is made of cheese (notice lack of single quotes on key?)
echo "the moon is made of {$foo['bar']}"; //the moon is made of cheese
As you can see there are different way to play with strings. If I'm putting variables inside a double quoted string I'll usually opt for the curly brace syntax {} since it doesn't bail in method calls or arrays. Otherwise I'll just concatenate....
Code: Select all
echo 'the moon is made of '.$foo['bar']; //the moon as made of cheese
What was the question again?
