Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z logowaniem - brak reakcji na poprawne dane
Osth
post 31.01.2013, 23:40:44
Post #1





Grupa: Zarejestrowani
Postów: 15
Pomógł: 0
Dołączył: 29.12.2012

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


Witam. Tak jak w temacie; jak podam prawidłowe dane w formularzu w którym action="login.php?cmd=zaloguj" to tylko odświeża mi stronę i formularz dalej jest, natomiast jak podam błdne dane, wyświetla się komunikat, że błędne, czyli działa tak jak powinno. Co jest więc nie tak z tą pierwszą częścią?

  1. <?php
  2. include 'config.php';
  3.  
  4.  
  5. if(empty($_GET) && $_COOKIE['zalogowany']=='y' && $_SESSION['login']=='zalogowany') { panel(); }
  6. elseif(empty($_GET)) {
  7. echo'Zaloguj się.';
  8. }
  9. if($_GET['cmd'] == 'panel') { panel(); }
  10. if($_GET['cmd'] == 'zaloguj') { login2(); }
  11. if($_GET['cmd'] == 'wyloguj') { logout(); }
  12.  
  13.  
  14.  
  15. function panel() {
  16. echo 'panel';
  17. }
  18.  
  19. function login2() {
  20.  
  21. $id = addslashes(htmlspecialchars($_POST['id']));
  22. $haslo = addslashes(htmlspecialchars($_POST['haslo']));
  23.  
  24. $sql = "SELECT * FROM `uzytkownicy` WHERE `id` = '$id'";
  25. $query = mysql_query($sql);
  26.  
  27. $r = mysql_fetch_array($query);
  28. $xid = $r['id'];
  29. $xhaslo = $r['haslo'];
  30. $bazaimie = $r['imie'];
  31.  
  32. if($id == $xid && $haslo == $xhaslo) {
  33. $_SESSION['login'] = 'zalogowany';
  34. $_SESSION['id'] = $r['id'];
  35. setcookie('zalogowany', 'y', time()+3600);
  36. header('location: index.php');
  37. }
  38. else {
  39. theme_start();
  40. theme_content();
  41. echo'Podałeś nieprawidłowe dane.';
  42. theme_stop();
  43. }
  44. }
  45.  
  46. function logout() {
  47.  
  48. setcookie('zalogowany', 'y', time()-3600);
  49. header('location: index.php');
  50. }
  51.  
  52. ?>
  53.  
  54.  
Go to the top of the page
+Quote Post
Damonsson
post 1.02.2013, 00:20:19
Post #2





Grupa: Zarejestrowani
Postów: 2 355
Pomógł: 533
Dołączył: 15.01.2010
Skąd: Bydgoszcz

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


po przekierowaniu masz samo index.php?
startujesz gdzieś sesję?
wartości w sesji po przekierowaniu są poprawne? print_r($_SESSION)
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 16.06.2025 - 21:52