i get coockie value by javascript :

-----------start code ---------
<html>

<script language="JavaScript">
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}
</script>

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<script language="JavaScript">
$loginval =(readCookie("isforumlogin"));
$loginid =(readCookie("useridforum"));
</script>
</body>
</html>

------end code----

But i wish put this (php) code in body :

<?php
mysql_connect("host", "username", "password") or die("Could not connect");
mysql_select_db("database") or die(mysql_error());

$UserD = $loginid
$sql = mysql_query("SELECT UserName FROM users WHERE id = $UserD ");
fetch_em = mysql_fetch_array($sql);
echo fetch_em["username"];
?>

how can i set $UserD = $loginid ????

thanks

    PHP runs on the server, and JS runs on the client, so you have to send the variables to the server somehow. That means that you'll need to refresh the page, or post a form, or something....You can't pass it to PHP without refreshing the page.

    Diego

      why not do

      if (isset($COOKIES['useridforum'])) $UserD = $COOKIES['useridforum'];

      you can access cookies with php, you don't need to use javascript

        Agreed; PHP is the thing for cookies, in most circumstances.

        Compare OP's long function to Roy's one liner....I know which is for me.

        Not to quash javascript...

        Behzad, you could have Javascript post into the SESSION array via another window, then destroy it, but, as has been noted, it wouldn't be an efficient thing to do....

          Write a Reply...