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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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