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
    • 241
    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:-

    1. <input type='hidden' name='post_id' value='".createPassword(64)."'>
    2. Then in your code do this:
    3.  
    4. if( ($_SESSION['post_id'] != $_POST['post_id']) )
    5. {
    6. $&_SESSION['post_d'] = $_POST['post_;id'];
    7. //do post stuff
    8. } else {
    9. //normal display
    10. }
    11.  
    12. function createPassword($length)
    13. {
    14. $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    15. srand((double)microtime()*1000000);
    16. $i = 0;
    17. $pass = '' ;
    18.  
    19. while ($i <= ($length - 1)) {
    20. $num = rand() % 33;
    21. $tmp = substr($chars, $num, 1);
    22. $pass = $pass . $tmp;
    23. $i++;
    24. }
    25. return $pass;
    26. }

    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
Reset Password
Fill out the form below and reset your password: