SilverFox1405241541 0 Report post Posted June 13, 2007 In this tutorial I show a JS/PHP Timer. I use ingame password resetting as an example. I did borrow the JS from another online tutorial but the rest I did on my own. It works as its the source from my pass reset mostly. <?phpif ($action == 'action1') // this is the action being performed, example: index2.php?page=passreset{// Process ID would go here. It has the user's id, and other things depending on the process. However because this is used to fetch the process from the DB it cannot have things like time or date as thy change on the next page.//checks the processes table$check1 = mysql_query("SELECT * FROM ha_processes WHERE ID_MEMBER='$id'")or die(mysql_error()); $time_to_finish =60; // time to finish the process. This can have other variables but for this example its simple.// defines the process start time, the process name and the user starting the process. This starts the process.$start = mysql_query("INSERT INTO ha_processes (ID_MEMBER, name, started, tofinish, p_id) VALUES ('$id', 'PassReset', '$now', '$time_to_finish', '$p_id')")or die(mysql_error());?>Action being performed<script language="javascript">var loadedcolor='darkgray'; // PROGRESS BAR COLORvar unloadedcolor='lightgrey'; // COLOR OF UNLOADED AREAvar bordercolor='navy'; // COLOR OF THE BORDERvar barheight=15; // HEIGHT OF PROGRESS BAR IN PIXELSvar barwidth=300; // WIDTH OF THE BAR IN PIXELSvar waitTime=<?php echo $time_to_finish; ?>; // NUMBER OF SECONDS FOR PROGRESSBAR// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100%.// IF NO ACTION IS DESIRED, TAKE EVERYTHING OUT FROM BETWEEN THE CURLY BRACES ({})// PRESENTLY, IT IS SET TO DO NOTHING, BUT CAN BE CHANGED EASILY.// TO CAUSE A REDIRECT TO ANOTHER PAGE, INSERT THE FOLLOWING LINE:// document.location.href="http://redirect_page.html";// JUST CHANGE THE ACTUAL URL OF COURSE :)var action=function(){hidebar();document.location.href="index2.php?action=passresetted"; // at leaset in our pass reset example}// THE FUNCTION BELOW CONTAINS THE ACTION(S) TO TAKE PLACE IF THE USER// CLICKS THE TIMERBAR. THIS CAN BE USED TO CANCEL THE TIMERBAR.// IF YOU WISH NOTHING TO HAPPEN, SIMPLY REMOVE EVERYTHING BETWEEN THE CURLY BRACES.var clickBar=function(){}//*****************************************************////********** DO NOT EDIT BEYOND THIS POINT **********////*****************************************************//var ns4=(document.layers)?true:false;var ie4=(document.all)?true:false;var blocksize=(barwidth-2)/waitTime/10;var loaded=0;var PBouter;var PBdone;var PBbckgnd;var Pid=0;var txt='';if(ns4){txt+='<table border=0 cellpadding=0 cellspacing=0><tr><td>';txt+='<ilayer name="PBouter" visibility="hide" height="'+barheight+'" width="'+barwidth+'" onmouseup="clickBar()">';txt+='<layer width="'+barwidth+'" height="'+barheight+'" bgcolor="'+bordercolor+'" top="0" left="0"></layer>';txt+='<layer width="'+(barwidth-2)+'" height="'+(barheight-2)+'" bgcolor="'+unloadedcolor+'" top="1" left="1"></layer>';txt+='<layer name="PBdone" width="'+(barwidth-2)+'" height="'+(barheight-2)+'" bgcolor="'+loadedcolor+'" top="1" left="1"></layer>';txt+='</ilayer>';txt+='</td></tr></table>';}else{txt+='<div id="PBouter" onmouseup="clickBar()" style="position:relative; visibility:hidden; background-color:'+bordercolor+'; width:'+barwidth+'px; height:'+barheight+'px;">';txt+='<div style="position:absolute; top:1px; left:1px; width:'+(barwidth-2)+'px; height:'+(barheight-2)+'px; background-color:'+unloadedcolor+'; font-size:1px;"></div>';txt+='<div id="PBdone" style="position:absolute; top:1px; left:1px; width:0px; height:'+(barheight-2)+'px; background-color:'+loadedcolor+'; font-size:1px;"></div>';txt+='</div>';}document.write(txt);function incrCount(){loaded++;if(loaded<0)loaded=0;if(loaded>=waitTime*10){clearInterval(Pid);loaded=waitTime*10;setTimeout('action()',100);}resizeEl(PBdone, 0, blocksize*loaded, barheight-2, 0);}function hidebar(){clearInterval(Pid);if(ns4)PBouter.visibility="hide";else PBouter.style.visibility="hidden";}function findlayer(name,doc){var i,layer;for(i=0;i<doc.layers.length;i++){layer=doc.layers[i];if(layer.name==name)return layer;if(layer.document.layers.length>0)if((layer=findlayer(name,layer.document))!=null)return layer;}return null;}function progressBarInit(){PBouter=(ns4)?findlayer('PBouter',document):(ie4)?document.all['PBouter']:document.getElementById('PBouter');PBdone=(ns4)?PBouter.document.layers['PBdone']:(ie4)?document.all['PBdone']:document.getElementById('PBdone');resizeEl(PBdone,0,0,barheight-2,0);if(ns4)PBouter.visibility="show";else PBouter.style.visibility="visible";Pid=setInterval('incrCount()',95);}function resizeEl(id,t,r,b,l){if(ns4){id.clip.left=l;id.clip.top=t;id.clip.right=r;id.clip.bottom=b;}else id.style.width=r+'px';}window.onload=progressBarInit;</script><small>Total Time to execute: <code><?php echo $time_to_finish; ?> Seconds</code>.<?php}// if the JS timer finishesif ($action == 'passresetted'){p_id goes here$passg = mt_rand (100000, 100000000); // this determines the pass in this example. In other cases al the other determining this would go here.//checks the processes table$check2 = mysql_query("SELECT * FROM ha_processes WHERE ID_MEMBER='$id' AND p_id='$p_id'")or die(mysql_error()); $row2 = mysql_fetch_array($check2);// this gets the old log values. This is for ingame logs, something you probably won't need but still here.$logcheck = mysql_query("SELECT * FROM logs WHERE ID_MEMBER='$id'")or die(mysql_error());$logs = mysql_fetch_array($logcheck);$logtime = date("D M d G:m Y");$log_ent = "\[$logtime\] \[localhost\] \[reset password FROM ";$log_ent2 = "$us2[Pass] TO xxxxxxxxx\]\n";$log_add = $log_ent.$log_ent2.$logs['log'];// this determines if the time is upif ($now - $row2['started'] >= $row2['tofinish']){// this actually updates the user's account$reset2 = mysql_query("UPDATE vpcs SET Pass='$passg' WHERE ID_MEMBER='$id'")or die(mysql_error());// this sends something to the ingame logs, logging the action$logsend = mysql_query("UPDATE logs SET log='$log_add' WHERE ID_MEMBER='$id'")or die(mysql_error());// this removes teh processes from the table. this is down to save space.$reset = mysql_query("DELETE FROM ha_processes WHERE ID_MEMBER='$id' AND p_id='$p_id'") ordie(mysql_error());echo "<code>R00t</code> Password Reset from ".$us2['Pass']." to ".$passg;}}?>This took me a while to make, I hope it helps someone. you can make it as variable as you want (I have edited it to be effected by in game software, hardware, etc and have made very unique but repeatable process IDs). Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted June 17, 2007 Great example, this kind of things are very requested, i think that i see more than once here at the forum.BTW, don't you think that it would be better if you post a working link to view it in action??? if it is not possible to share it to the community can you please PM me because i'm interested.Best regards, Share this post Link to post Share on other sites
iGuest 3 Report post Posted May 23, 2008 PHP- timer and printer function Js/php/mysql Timer Hi : I have 2 questions ,maybe that is a big demand : 1.Can you please send me and example of php code which is able to configure.Set and use printer in order to print a page or string >? I don't know how should I use printer function 2.How can I use a time .For instance --> If($c>0) then go to ("a.Php") for 10 second , after finishing the 10 second ,go to ("index.Php") -question by Arash Share this post Link to post Share on other sites