Forum Moderators: coopster

Message Too Old, No Replies

Javascript Cookies

can PHP read them

         

WhosAWhata

11:03 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



I was wondering if/how PHP can read cookies set in JavaScript.

"google"ing the question provided links to javascript cookies and php cookies but no combination of the two

sned

11:11 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



It's my understanding that a cookie is a cookie no matter what language sets it .. just an entry in a text file somewhere.

I think you can read cookies with the $_COOKIE[] array, and set them using the setcookie [us2.php.net] function.

-sned

WhosAWhata

11:49 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



you are absolutely correct
i tested using this simple script


<?
if($_COOKIE){
echo "<table>";
foreach($_COOKIE as $c => $v){
echo "<tr><td>".$c."</td><td>".$v."</td></tr>";
}
echo "</table>";
}
?>
<script type="text/javascript">
function setCookie(name, value)
{
document.cookie= name + "=" + escape(value);
}
</script>
name:<input type=text id=name><br>value:<input type=text id=stuff><br><Br>
<br><br>
<form action="<?=$PHP_SELF?>" method=post onSubmit="setCookie(document.all.name.value,document.all.stuff.value);">
<input value=set type=submit></form>

it really has no purpose other than to test the cookies
javascript cookies are set, then the page is reloaded and the php section reads off every set cookie