Advertisement
Guest User

Untitled

a guest
Sep 14th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2. //signin.php
  3. include 'connect.php';
  4. include 'header.php';
  5.  
  6. echo '<h3>Sign in</h3>';
  7.  
  8. //first, check if the user is already signed in. If that is the case, there is no need to display this page
  9. if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true)
  10. {
  11. echo 'You are already signed in, you can <a href="signout.php">sign out</a> if you want.';
  12. }
  13. else
  14. {
  15. if($_SERVER['REQUEST_METHOD'] != 'POST')
  16. {
  17. /*the form hasn't been posted yet, display it
  18. note that the action="" will cause the form to post to the same page it is on */
  19. echo '<form method="post" action="">
  20. Username: <input type="text" name="user_name" />
  21. Password: <input type="password" name="user_pass">
  22. <input type="submit" value="Sign in" />
  23. </form>';
  24. }
  25. else
  26. {
  27. /* so, the form has been posted, we'll process the data in three steps:
  28. 1. Check the data
  29. 2. Let the user refill the wrong fields (if necessary)
  30. 3. Varify if the data is correct and return the correct response
  31. */
  32. $errors = array(); /* declare the array for later use */
  33.  
  34. if(!isset($_POST['user_name']))
  35. {
  36. $errors[] = 'The username field must not be empty.';
  37. }
  38.  
  39. if(!isset($_POST['user_pass']))
  40. {
  41. $errors[] = 'The password field must not be empty.';
  42. }
  43.  
  44. if(!empty($errors)) /*check for an empty array, if there are errors, they're in this array (note the ! operator)*/
  45. {
  46. echo 'Uh-oh.. a couple of fields are not filled in correctly..';
  47. echo '<ul>';
  48. foreach($errors as $key => $value) /* walk through the array so all the errors get displayed */
  49. {
  50. echo '<li>' . $value . '</li>'; /* this generates a nice error list */
  51. }
  52. echo '</ul>';
  53. }
  54. else
  55. {
  56. include 'connect.php';
  57. if(!mysqli_connect($server, $username, $password, $database))
  58. $sql = "SELECT
  59. user_id,
  60. user_name,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement