Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Logowanie na sesjach
mat_1200
post
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

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


Witam. Mam problem. Otóż napisałem skrypt logowania na sesjach:
  1. <?
  2.  
  3. $_SESSION['login'] = $_POST['login'];
  4. $_SESSION['pass'] = $_POST['pass'];
  5. $auth = 0;
  6.  
  7.  
  8.  
  9. $read = fread(fopen("user.dat", "r"), filesize("user.dat"));
  10.  
  11. while($i <= sizeof($read)){
  12. $uzer = explode("|", $read[$i]);
  13. if ($uzer[0] == $_SESSION['login'] and $uzer[1] == $_SESSION['pass']){
  14. $auth = 1;
  15. } else {
  16. $auth = 0;
  17. }
  18. }
  19.  
  20. if ($auth == 1){
  21. $_SESSION['loged'] = 'true';
  22. echo'Zalogowany jako '.$_SESSION['login'];
  23. }
  24. else
  25. echo'<font color="red"><b>Niepoprawny login lub hasło!</b></font>';
  26.  
  27. ?>

I na zalogowanie czekam "120 seconds". Wyswietla mi błąd. Pomóżcie...

Ten post edytował mat_1200 24.12.2005, 01:49:26
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
vala
post
Post #2





Grupa: Zarejestrowani
Postów: 123
Pomógł: 0
Dołączył: 12.01.2005

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


To co napisales jest z leksza bez sensu:)

Kod
while($i <= sizeof($read))


z tej petli skrypt nigdy nie wyjdzie. A jak juz sie koniecznie upierasz przy plikach to polecam
file" title="Zobacz w manualu php" target="_manual

gdzie '\n' jest delimeterem kazdego nowego elementu tablicy ,z ktorej wyciagasz string podzielony '|' .

Ten post edytował vala 24.12.2005, 03:16:21


--------------------
Warsztat: Easy PHP 1.7:Apache 1.3.27|PHP 4.3.3|PHPMYADMIn 2.5.3|MYSQL 4.0.15
Go to the top of the page
+Quote Post
mat_1200
post
Post #3





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

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


To mam pytanie jak to napisać??
Go to the top of the page
+Quote Post
Hacker
post
Post #4





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

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


Może jeszcez Ci na serwer to wrzucić??... Ehhh
  1. <?php
  2. $_SESSION['login'] = $_POST['login'];
  3. $_SESSION['pass'] = $_POST['pass'];
  4. $auth = 0;
  5.  
  6.  
  7.  
  8. $read = file('user.dat');
  9.  
  10. for ($i=0; $i < count($read); $i++){
  11. $uzer = explode("|", rtrim($read[$i]));
  12. if ($uzer[0] == $_SESSION['login'] and $uzer[1] == $_SESSION['pass']){
  13. $auth = 1;
  14. } else {
  15. $auth = 0;
  16. }
  17. }
  18.  
  19. if ($auth == 1){
  20. $_SESSION['loged'] = 'true';
  21. echo'Zalogowany jako '.$_SESSION['login'];
  22. }
  23. else
  24. echo'<font color="red"><b>Niepoprawny login lub hasło!</b></font>';
  25.  
  26. ?>


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
Go to the top of the page
+Quote Post
mat_1200
post
Post #5





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

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


Mam problem bo powyższy kod odczytuje tylko ostatniego usera. A chce zeby wszystkich odczytywalo. Jak to zrobić??
Go to the top of the page
+Quote Post
Hacker
post
Post #6





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

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


  1. <?php
  2. for ($i=0; $i < count($read); $i++){
  3. $uzer = explode("|", rtrim($read[$i]));
  4. if ($uzer[0] == $_SESSION['login'] and $uzer[1] == $_SESSION['pass']){
  5. $auth = 1;
  6. break;
  7. } else {
  8. $auth = 0;
  9. }
  10. }
  11. ?>


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
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 Aktualny czas: 19.08.2025 - 21:21