Jump to content

Embed PHP in Javascript


akshay

Recommended Posts

Hi.

 

I'm working on this JS Countdown timer (I'm a PHP Programmer, not a JS!)

 

Anyone knows how to set TargetDate & FinishMessage variable?

 

I've tried it as shown below, but it assumes PHP inserted value <?php...?> to be undefined as shows default values from countdown.js

 

<html>
<body bgcolor="#8cc63e" >
<font face="Verdana" style="font-size: 24" color="white">

<?php
session_start();
date_default_timezone_set("UTC");

if (!isset($_GET['f']) || !isset($_GET['s']) || !isset($_GET['dlpath']) || !isset($_GET['sessid'])) {
echo "<b>INVALID <br> REQUEST</b>";
exit;
} else {

$realsessid=session_id();
$sessid=$_GET['sessid'];

if ($sessid!=$realsessid) {
echo "<b>INVALID <br> REQUEST</b>";
exit;
}
}

$s=$_GET['s'];
$f=$_GET['f'];
$dlpath=urlencode($_GET['dlpath']);
$dlpathtok=md5($dlpath);

$link= '<a href="http://my-site.web/dl/launchdl.php?f='.$f.'&dlpath='.$dlpath.'&sessid='.$sessid.'&dlpathtok='.$dlpathtok.' " target="_blank"><img src="http://my-site.web/images/btn_download.png" alt="Download!" border=0></a>';
$time=time()+$s;
$target=date("m/d/Y h:i A",$time);
echo $target."<br><br>";
?>

<script language="JavaScript">
// TargetDate = "07/05/2010 9:00 AM" //By Default
TargetDate = "<?php echo $target; ?>"; //mine entered
BackColor = "#8cc63e";
ForeColor = "white";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = " %%S%% ";
FinishMessage = "HELLO";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>




</font>
</body></html>

Link to comment
https://forums.phpfreaks.com/topic/206782-embed-php-in-javascript/
Share on other sites

i try this part of code

<html>
<body bgcolor="#8cc63e" >
<font face="Verdana" style="font-size: 24" color="white">

<?php
$time=time()+20;
$target=date("m/d/Y h:i:s A",$time);
echo $target."<br><br>";
?>

<script language="JavaScript">
// TargetDate = "07/05/2010 9:00 AM" //By Default
TargetDate = "<?php echo $target; ?>"; //mine entered
BackColor = "#8cc63e";
ForeColor = "white";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = " %%S%% ";
FinishMessage = "HELLO";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>

</font>
</body></html>

an it works for me

dude. You'd see seconds counting down for sure...but it would become a loop, u see...

 

once they reach 0, they start again (it looks like a loop, but actually the code follows the date of 2020 as in JS...)

and u see, there's no finish msg displayed!

 

Or do u see one?

 

Thanks

OK, couple of things.

 

The script is looking at your display format, Currently you have it set to seconds, so if you enter in more than 60 seconds, it will loop until the counter reaches 0.

 

You can see this if you set the variable to:

DisplayFormat = " %%M%% Minutes %%S%% Seconds";

 

You would also need to make sure that your variable $s is an integer.

$s = (int)$_GET['s'];
//or
$s = int_val($_GET['s']);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.