Advertisement
thecodepress

Cross site request forgery (CSRF) Protection in PHP - 2

Mar 18th, 2014
4,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2.   session_start();
  3.  
  4.   if (isset($_POST['uname'], $_POST['token'])) {
  5.     if (!empty($_POST['uname']) && !empty($_POST['token'])) {
  6.       if (!Security::checkToken($_POST['uname'])) {
  7.         // Show the error or redirect on home page!
  8.         header('Location: index.php');
  9.         die();
  10.       }
  11.  
  12.       // Succeed!
  13.       print_r($_POST);
  14.     }
  15.   }
  16. ?>
  17. <html>
  18.   <head>
  19.     <title>CSRF - TheCodePress</title>
  20.   </head>
  21.   <body>
  22.     <form action="index.php" method="POST">
  23.       <label>Email:</label><br />
  24.       <input type="text" name="uname" placeholder="Username" />
  25.       <input type="hidden" name="token" value="<?php echo Security::getToken(); ?>" />
  26.     </form>
  27. </body>
  28. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement