Jump to content

Refreshing is not allowed. PHP


LOUDMOUTH

Recommended Posts

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! :)

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

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.

Archived

This topic is now archived and is closed to further replies.

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