PHP Code:
<html>
<head>
<title> passing vars between JS and PHP </title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
<meta name="mssmarttagspreventparsing" content="true">
</head>
<body>
<?
echo <<<EOF
<script language="javascript" type="text/javascript">
userTime = new Date ();
function showTime()
{
document.write ('Javascript Output: ' + userTime);
}
</script>
EOF;
echo "<br><br><br>";
echo "<br>PHP Output 1: ";
echo "line 41: " . $userTime; // doesn't work!!!
echo "<br><br><br>";
$userTime = "<script>document.write(userTime);</script>";
echo "PHP Output 2 - line 44: " . $userTime; // works !
?>
<br><br><br>
JS-Output: <br>
<script>document.write(userTime);</script>
<br><br><br>
PHP, again: <?=$userTime;?>
</body>
</html>
This is just to demonstrate how to define a var and then pass it on to php.
You can then use e.g.
SET userTime='$userTime' later on for your DB.
Bookmarks