Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. $dbc = mysqli_connect('localhost', 'root', '', 'lesson');
  3. if(!isset($_COOKIE['user_id'])) {
  4. if(isset($_POST['submit'])) {
  5. $user_username = mysqli_real_escape_string($dbc, trim($_POST['username']));
  6. $user_password = mysqli_real_escape_string($dbc, trim($_POST['password']));
  7. if(!empty($user_username) && !empty($user_password)) {
  8. $query = "SELECT `user_id` , `username` FROM `signup` WHERE username = '$user_username' AND password = SHA('$user_password')";
  9. $data = mysqli_query($dbc,$query);
  10. if(mysqli_num_rows($data) == 1) {
  11. header('Location: index.php');
  12. $row = mysqli_fetch_assoc($data);
  13. setcookie('user_id', $row['user_id'], time() + (60*60*24*30));
  14. setcookie('username', $row['username'], time() + (60*60*24*30));
  15. }
  16. else {
  17. echo 'Sorry,you should correctly write password!';
  18. }
  19. } else {
  20. echo 'Correct the fields!';
  21. }
  22. }
  23. }
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement