Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Problem z logowaniem poprzez session
przemo191
post
Post #1





Grupa: Zarejestrowani
Postów: 154
Pomógł: 3
Dołączył: 1.08.2011

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


Witam mam taki problem, zrobiłem skrypt logowania, który sprawdza poprawność pola login i hasło z bazą danych. Kiedy wpisujemy złe dane do formularza logowania skrypt zachowuje się jak należy, natomiast kiedy wpiszemy dobre dane to wywala błąd:
Notice: Undefined index: test in C:\wamp\www\depis\baza_napraw\loguj.php on line 42

Kod php to:
  1. <?php
  2.  
  3. $user1 = $_POST['user'];
  4. $pass1 = $_POST['password'];
  5. $typ_bazy = $_POST['typ_bazy'];
  6.  
  7. $user2 = ($user1);
  8. $pass2 = md5($pass1);
  9.  
  10. include("../db_pass.php");
  11. mysql_connect($host,$username,$password);
  12. mysql_select_db($database) or die("Nie odnaleziono bazy danych");
  13. $query="SELECT * FROM account WHERE USER='$user2' and TYP_BAZY='$typ_bazy' and PASSWORD='$pass2'";
  14. $result=mysql_query($query);
  15. $num=mysql_numrows($result);
  16.  
  17. $i=0;
  18. while ($i < $num) {
  19. $user3 = mysql_result($result,$i,"USER");
  20. $pass3 = mysql_result($result,$i,"PASSWORD");
  21. $i++;
  22. }
  23.  
  24. if($pass2 = $pass3){
  25. $pass4 = "$pass2";
  26. }else{
  27. header('Location: index.html');
  28. }
  29.  
  30. if($user2 = $user3){
  31. $user4 = "$user2";
  32. }else{
  33. header('Location: index.html');
  34. }
  35.  
  36.  
  37. function loguj($user, $password){
  38. $users['$user3'] = '$pass3';
  39.  
  40. if($users[$user] == $password && $password != "") {
  41. $_SESSION['is_logged'] = true;
  42. return true;
  43. }
  44. else {
  45. return false;
  46. }
  47. }
  48.  
  49. if(loguj("$user4", "$pass4")){
  50. if(!isset($_SESSION['redirect_to'])) $to = 'startowa.php';
  51. else {
  52. $to = $_SESSION['redirect_to'];
  53. }
  54. header('Location: '.$to);
  55. }
  56. else {
  57. header('Location: index.html');
  58. }
  59. ?>


Nie wiem gdzie jest błąd.
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 21.08.2025 - 19:14