Hello.

I don't know any code of Javascript. I programme in PHP.

I grabbed this piece of code for javascript timer:

<form name="counter"><input name="d2" type="text" size="8" style="font-size:72pt; border:none; font-family:Verdana; color:#00BFFF; text-outline: 1px 1px #009ACD;"></form>

<script> 
<!-- 
// 
 var milisec=0 
 var seconds=<?php echo $s;?>
 document.counter.d2.value='0' 

function display(){ 
 if (milisec<=0){ 
    milisec=9 
    seconds-=1 
 } 
 if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
 } 
 else 
    milisec-=1 
    document.counter.d2.value=seconds
    setTimeout(\"display()\",100) 
} 
display() 
--> 
</script>

Basically the count-down timer code displays seconds counting down in textbox "d2".
I've modified the code to display seconds only and no milliseconds.

After the countdown, I've used PHP.
For example: If $s=45 (let).
The code countsdown, while simultaneously, a header is sent:
header("refresh: $s; http://..../...sameurl.php?s=RANDOM_TEMP_PASSWORD");
So that page refreshes after say 45 seconds and sends itself a random password, instructing the page that timer is now set to '0' and it should show the "DOWNLOAD" button.

In Mozilla Firefox, Download button appears after refresh

However, In IE6/7/8 after refresh, the timer restarts instead of showing "Download"

Live Example: http://www.mintload.com/dl/?f=cf51a94

(Click "FREE DOWNLOAD", and see the page freedl.php on next page which has this problem on IE)

Thank you!

Please help me fix this prob., It's really urgent.
Thanks

As this is urgent, iil give you the solution, but study the code and learn from your mistakes. Each code lines needs to end with a ;, use more spaces and pay attention on how I use the setTimeout() function:

setTimeout(function(){
//Here should be all the code you want executed
}, 0);

And here how it is implemented:

<script type='text/javascript'> 
<!-- 

 var milisec=0;
 var seconds=<?php echo $s;?>;
 // I directed this (document.counter.d2.value='0';) to setTimeout, as the document has not yet been loaded

function display(){ 
 if (milisec <= 0){ 
    milisec = 9;
    seconds -= 1; 
 } 
 if (seconds <= -1){ 
    milisec = 0;
    seconds += 1;
 } else {
    milisec-=1;
    document.counter.d2.value=seconds;
    setTimeout(function(){ display(); },100);
 }
} 
window.onload=function() {
document.counter.d2.value='0';
display();
}
--> 
</script>

~G

The full code (PHP + Javascript on timer3.php) s here:

<?php

session_start();


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

$s=waitfor(); //function returns how many seconds to wait.
$link='<a href="http://mintload.com/dl/launchdl.php?f='.$f.'&dlpath='.$dlpath.'&sessid='.$sessid.'" target="_blank"><img width=195 height=45 src="http://mintload.com/images/btn_download.png" alt="Download!" border=0></a>';

global $zerowait;
$zerowait=md5("secret_password".session_id()); //temperory session-id based password (hash) instructing that seconds to wait is 0.

if($_GET['s']!=$zerowait)
{
//Display seconds, and after $s seconds (returned by func) , refresh the page.
header("refresh: $s; http://mintload.com/dl/timer3.php?s=".$zerowait."&f=$f&dlpath=$dlpath&sessid=$sessid");
echo '<form name="counter"><input type="text" size="8" style="font-size:72pt; border:none; font-family:Verdana; color:#00BFFF; text-outline: 1px 1px #009ACD;" name="d2"></form>';

}
else {
//if $s=-zerowait, set seconds to 0 (stops javascript timer), display "download" button ($link), and exit rest of script

$s=(int)0;
echo $link;
exit;
}

echo "

<script> 
<!-- 
// 
 var milisec=0 
 var seconds=$s
 document.counter.d2.value='0' 

function display(){ 
 if (milisec<=0){ 
    milisec=9 
    seconds-=1 
 } 
 if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
 } 
 else 
    milisec-=1 
    document.counter.d2.value=seconds
    setTimeout(\"display()\",100) 
} 
display() 
--> 
</script>"; 


function waitfor() {

//Code suppressed as it works fine (waitfor())

/* Basically what function does is:  
if premium user, $s=0;
if free users, $s=30;
if unregistered user, $s=45;
return $s;
*/

} //func ends

?>

Now, could u please relate and help???

Thank you!

Look, I was willing to correct your code and remove the syntax errors. Apply my code, and work the PHP out yourself. The JavaScript timer should work. Also check the HTML source code for wrong output.

~G

The only error in my script was:
header("refresh: $s; http:/....");

should BE:
header("refresh: $s url=http:/..."); //WORKS IN ALL BROWSERS! Those 3 letters, url

anyway, Thanks all those who helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.