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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.