Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Logowanie
Mastroeni7
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 22.02.2011

Ostrzeżenie: (0%)
-----


Chcę, aby mój skrypt przekierowywał admina na inną stronę, oraz użytkownika na inną. Problemem jest to, że co nie wpiszę przechodzi mi tylko do 'user.php' Może powiecie co jest nie tak ? Na początku jeszcze wyskakuje mi błąd Notice: Undefined index: login in /home/***//logowanie.php on line 10
  1. <?php
  2.  
  3. include ('db.php');
  4. function clean($value) {
  5. if(get_magic_quotes_gpc()) $value = stripslashes($value);
  6. return trim(mysql_real_escape_string($value));
  7. }
  8.  
  9. if($_POST['login'] && $_POST['username'] && $_POST['password']) {
  10. $username = clean($_POST['username']);
  11. $password = md5($_POST['password']);
  12.  
  13. $isAdmin = mysql_query("SELECT count(*) FROM users WHERE user_name = '$username' AND user_type = '1'");
  14. if(mysql_num_rows($isAdmin) == 1) {
  15. header("Location: admin.php");
  16. }
  17.  
  18. $result = mysql_query("SELECT count(*) FROM users WHERE user_name = '$username' AND user_password = '$password' and user_type='2'");
  19. if(mysql_num_rows($result) == 1) {
  20. $_SESSION['username'] = $username;
  21. header("Location: user.php");
  22. } else {
  23. header("Location: opps.php");
  24. }
  25. }
  26.  
  27.  
  28. ?>
  29. formularz w htmlu

user_type = 1, mam w mysql dla admina, user_type = 2, dla użytkownika
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


  1. if(!empty($_POST['username']) && !empty($_POST['password'])) {
  2.  
  3. $username = clean($_POST['username']);
  4. $password = md5($_POST['password']);
  5.  
  6. $query = mysql_query("SELECT password, user_type FROM users WHERE user_name = '$username'");
  7.  
  8. if(mysql_num_rows($query)) {
  9.  
  10. $row = mysql_fetch_array($query);
  11.  
  12. if($row['password'] == $password) {
  13.  
  14.  
  15. $_SESSION['username'] = $username;
  16.  
  17. switch($row['user_type']) {
  18.  
  19. case 1:
  20. $_SESSION['user_type'] = 1;
  21. header("Location: admin.php");
  22. break;
  23.  
  24. case 2:
  25. $_SESSION['user_type'] = 2;
  26. header("Location: opps.php");
  27. break;
  28.  
  29. default:
  30. header("Location: index.php");
  31. break;
  32. }
  33. }
  34. }
  35. else {
  36.  
  37. header("Location: login.php");
  38. }
  39. }
  40. else {
  41. header("Location: login.php");
  42. }
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 11:56