LOUDMOUTH Posted March 29, 2009 Share Posted March 29, 2009 I am looking for a code to stop someone from refreshing a page. Its will display this: "Refreshing is not allowed." Anyone know the string? Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/ Share on other sites More sharing options...
Mchl Posted March 29, 2009 Share Posted March 29, 2009 Not possible in PHP. Maybe in JavaScript What's next? 'Closing browser not allowed'? Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796387 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2009 Share Posted March 29, 2009 You cannot control what someone does with their browser. What problem are you having when someone refreshes a page? You will need to detect and prevent the problem in the server side code. Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796391 Share on other sites More sharing options...
Mikedean Posted March 29, 2009 Share Posted March 29, 2009 I'm guessing it's after someone has filled in a form (or something similar?) Perhaps setting a session variable after submitting the form, checking if it's set and then deleting it at the end of the script you want to stop refreshing in? Hope this helps! Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796392 Share on other sites More sharing options...
ToonMariner Posted March 29, 2009 Share Posted March 29, 2009 preventing default behaviour is a sure fire way to alienate users. If your site is breaking because of it then your application design is wrong. if this is one of hose instances where your page is performing an action that would be repeated on refresh (like remove/adding a record to a database etc.) then you should use header('Location: ...'); after the database update to send the user to a page that can be refreshed and even hit back on that won't repeat the update.. Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796394 Share on other sites More sharing options...
LOUDMOUTH Posted March 29, 2009 Author Share Posted March 29, 2009 It is possible in PHP. I am on a page right now and when I hit F5 it tells me "Refreshing is not allowed." "Back" I want this on one of the pages on my game to prevent Refresh. Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796407 Share on other sites More sharing options...
LOUDMOUTH Posted March 29, 2009 Author Share Posted March 29, 2009 this was in the source code <div class="g_text"> Refreshing is not allowed.<br><a href="/crime.php">Back</a></div> Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796409 Share on other sites More sharing options...
ToonMariner Posted March 29, 2009 Share Posted March 29, 2009 that is javascript and anyone caneasily turn javascript off Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796410 Share on other sites More sharing options...
ToonMariner Posted March 29, 2009 Share Posted March 29, 2009 if you can see it in the scource code of the page then its not php. php is long gone once the markup is served out to the browser Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796411 Share on other sites More sharing options...
LOUDMOUTH Posted March 29, 2009 Author Share Posted March 29, 2009 I figured it was echoing from a table in the database to stop a session or something along those lines. I am no coder though, haha. Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796412 Share on other sites More sharing options...
LOUDMOUTH Posted March 29, 2009 Author Share Posted March 29, 2009 I guess this might be the answer <script language="javascript"> function document.onkeydown() { if ( event.keyCode==116) { event.keyCode = 0; event.cancelBubble = true; return false; } } </script> Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796419 Share on other sites More sharing options...
killah Posted March 29, 2009 Share Posted March 29, 2009 It's honeslty not hard at all. Your Form: <?php session_start(); $rand = rand(1,99999); $_SESSION['rfc'] = $rand; echo ' <form action="process.php" method="post"> <input type="hidden" name="rfc" value="'.$rand.'"> <input type="text" name="text" value="SomeThing"> <input type="submit" value="Process"> </form>'; Now process.php <?php session_start(); if(isset($_POST['rfc'])) { if($_SESSION['rfc'] != $_POST['rfc']) { echo 'Refreshing not allowed.'; } else { echo 'Process the form.'; } //Unset session['rfc'] so it can not be used again. unset($_SESSION['rfc']); } And viola, no more refreshing. Link to comment https://forums.phpfreaks.com/topic/151650-refreshing-is-not-allowed-php/#findComment-796428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.