Kryllster Posted August 16, 2008 Share Posted August 16, 2008 Is there a way for me to prevent someone from hitting their back button and running a script over and over and over again?? Thanks In advance? Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/ Share on other sites More sharing options...
Fadion Posted August 16, 2008 Share Posted August 16, 2008 You cant disable such a functionality. It allows users to easily browse their history. Instead make the script act smartly. Post what problems are u having from the back button, maybe someone can give u an advice. Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-617746 Share on other sites More sharing options...
Kryllster Posted August 16, 2008 Author Share Posted August 16, 2008 Ok thanks for replying! Here is the code; <?php // initialize outcome of fight and loot chances $outcome = mt_rand(1,100); $level_advance = 2; $gold = mt_rand(1000,4000); $diamonds = mt_rand(3,; $rubies = mt_rand(3,7); // My Fight and loot generator $smarty->assign('gold',$gold); $smarty->assign('rubies',$rubies); $smarty->assign('diamonds',$diamonds); // First the fight if($outcome < 70){ // Connect to database include('includes/config.php'); include('includes/advance_level.php'); // Update database $sql="UPDATE $tbl_name SET onhand = onhand + $gold, diamond = diamond + $diamonds, rubie = rubie + $rubies, advance = advance + $level_advance WHERE uname='$uname'"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); $smarty->display('fight_success.tpl'); } else{ $smarty->display('fight_failure.tpl'); } ?> When the link that leads to this it goes thru an index contoller and executes the depending on the out come of course diplays the values like I wanted to, but all the person has to do is hit their back button on over and over wash rinse and repeat. I am learninf alot but this has me stymied. I was trying to do it where it runs the script then exits and directs it to the right page the first version worked better however I could not get the the variable output to the template?? Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-617748 Share on other sites More sharing options...
dezkit Posted August 16, 2008 Share Posted August 16, 2008 best solution is to have the form and the submit code on the same page i.e. <?php // codez if(isset($_POST["submit"])){ // if form is submitted } else { ?> <form action="" method="post"> FORMZ <input type="submit" value="submit" name="submit"> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-617750 Share on other sites More sharing options...
Kryllster Posted August 16, 2008 Author Share Posted August 16, 2008 Thanks for the reply I will work on that and get back once I see how it goes. Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-617752 Share on other sites More sharing options...
chronister Posted August 16, 2008 Share Posted August 16, 2008 Another solution would be to set a session var on the first run of the script which indicates that it has run already, then when running the script check for that session var and if it exists give the user a no-no message instead of running the script again. Something to that effect anyway. Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-617756 Share on other sites More sharing options...
Kryllster Posted August 16, 2008 Author Share Posted August 16, 2008 Could you explain how I could do that. Because the solution offered earlier would prolly work but I am using the Smarty template engine which I'm starting to see is a little advanced for me atm. I am thinking of converting to php / html strictly for now till I know more. Of course I am always full of questions so how do I make php templates and use a controller file?? Thanks, Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-617834 Share on other sites More sharing options...
chronister Posted August 17, 2008 Share Posted August 17, 2008 I don't know smarty at all. I have stayed away from it as I don't want to learn a "new language" to use PHP which I already know. But to do what I suggested you would do something like this. <?php session_start(); // start our session if(!isset($_SESSION['loot_chance_run'])) { // if $_SESSION['loot_chance_run] not set, proceed and run it $_SESSION['loot_chance_run'] = true; // set the session var now // initialize outcome of fight and loot chances $outcome = mt_rand(1,100); $level_advance = 2; $gold = mt_rand(1000,4000); $diamonds = mt_rand(3,; $rubies = mt_rand(3,7); // My Fight and loot generator $smarty->assign('gold',$gold); $smarty->assign('rubies',$rubies); $smarty->assign('diamonds',$diamonds); // First the fight if($outcome < 70){ // Connect to database include('includes/config.php'); include('includes/advance_level.php'); // Update database $sql="UPDATE $tbl_name SET onhand = onhand + $gold, diamond = diamond + $diamonds, rubie = rubie + $rubies, advance = advance + $level_advance WHERE uname='$uname'"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); $smarty->display('fight_success.tpl'); } else{ $smarty->display('fight_failure.tpl'); } } else { // give an error message and call them a cheater echo 'Sorry, this operation cannot be completed again cheater'; } ?> That is the basic premise of the code. There may be more to it depending on how many times this needs to run. At some point you may need to unset the session var to allow it to run depending on how the game is set up as this var will be set on all pages until you unset it. To unset it you use unset(). This also does not take into account any other operations you need to do such as calling the correct tpl file. <?php unset($_SESSION['loot_chance_run']); ?> Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-618302 Share on other sites More sharing options...
Kryllster Posted August 18, 2008 Author Share Posted August 18, 2008 Thanks I will copy and past this to see how it goes and will get back. The other script above you wrote actually works for a different application as well lol? I changed it a bit but its great for looking up stuff on the database. Anyway I will get back here later! Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-618840 Share on other sites More sharing options...
Kryllster Posted August 18, 2008 Author Share Posted August 18, 2008 Well it actually works better than I had hoped lol turns out this is exacly what I needed. Thank You so much for your help. I tested and with the final outcome of this whole section in my dungeon will be much better! Link to comment https://forums.phpfreaks.com/topic/119914-solved-is-there-a-solution-for-this/#findComment-618858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.