Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How you can stop the re submit of form using Unique id of form

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 236
    Comment on it

    Hello Reader's!, If you need a nice method to stop the form from again and again submit via refresh, PHP offers you many ways like header redriect or unset the $_POST but a pretty way is to implement a unique ID into the post and cache it in the

    Lets see the examle below:-

    <input type='hidden' name='post_id' value='".createPassword(64)."'>
    Then in your code do this:
    
    if( ($_SESSION['post_id'] != $_POST['post_id']) )
    {
        $&_SESSION['post_d'] = $_POST['post_;id'];
        //do post stuff
    } else {
        //normal display
    }
    
    function createPassword($length)
    {
        $chars = "abcdefghijkmnopqrstuvwxyz023456789";
        srand((double)microtime()*1000000);
        $i = 0;
        $pass = '' ;
    
        while ($i <= ($length - 1)) {
            $num = rand() % 33;
            $tmp = substr($chars, $num, 1);
            $pass = $pass . $tmp;
            $i++;
        }
        return $pass;
    }
    

    Now every time a unique ID will be genrated and if it match then only you proceed

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: