[thelist] javascript date into php

Bob Meetin bobm at dottedi.biz
Fri Jun 21 17:18:27 CDT 2013

I'm trying to employ javascript to obtain the local date and pull it into php. This partly works:

var currentTime = new Date()
var month = currentTime.getMonth()
var day = currentTime.getDate()
<?php $date = "<script>document.write(month + '/' + day)</script>"?>
<?php $jmonth = "<script>document.write(month)</script>"?>

echo "JavaScript Local Date: $date<br>";
$jmonth = chop($jmonth);
// $jmonth = (int)$jmonth; // fails
echo "jmonth: $jmonth<br>";
$pmonth = intval($jmonth); // no difference
$pmonth = $pmonth + 1;
echo "pmonth: $pmonth<br>";
if ( $pmonth > 5 ) { echo "Success"; } else { echo "Fail"; }

The javascript seems to be working and $jmonth reads the javascript value fine. However, once I get into PHP and attempt to do some simple math with the $jmonth/$pmonth value it falls apart. The php month gets interpreted as 0.

What am I missing?

More information about the thelist mailing list