rudzis Posted March 27, 2005 Report Share Posted March 27, 2005 Neesmu jau PHP guru, bet šo to uztaisīt māku. Nezinu kas par vainu manā primitīvajā login skriptā. login.php: <? $login = $_POST['login']; $password = $_POST['password']; $pass = file("../passwords.txt"); $log = "0"; foreach($pass as $user) { $case = explode(":|:", $user); if($login == $case[0] && $password == $case[1]) { $log = "1"; }} if($log == "1") { include('main.php'); } else { die("Ievadītie dati nav pareizi!"); } ?> passwords.txt - kreisajā pusē logini, labajā - paroles. es:|:mans tu:|:tavs Problēma tāda, ka vienkārši neielogojās un izmet die() uzrakstu. Kādam ir kādi varianti? Link to comment Share on other sites More sharing options...
bubu Posted March 27, 2005 Report Share Posted March 27, 2005 (edited) Šo rindiņu: $pass = file("../passwords.txt"); aizstāj ar $pass = array_map('trim', file("../passwords.txt")); Tas tāpēc, ka file atgriež faila saturu masīvā ar visiem enteriem rindiņu beigās. No manuāļa, kurā tev derēja pašam laikam ieskatīties: Each element of the array corresponds to a line in the file, with the newline still attached. Protams, šajā kodā logins un parole nevarēs saturēt atstarpes attiecīgi sākumā vai beigās. (korektāk būtu ifā salīdzinot paroli ņemt vērā enter simbolu: ... && $password == substr($case[1], 0, -1), un vispār - paroles glabāt plaintekstā nav sekjūri :) Edited March 27, 2005 by bubu Link to comment Share on other sites More sharing options...
LorDRameX Posted March 27, 2005 Report Share Posted March 27, 2005 $pass = file("../passwords.txt");$log = "0"; foreach($pass as $user) { $case = explode(":|:", $user); eeemm ejam un lasam: http://lv.php.net/fopen http://lv.php.net/fread man domaat ka tur jābūt kautka tā: $pass = fopen('../passwords.txt', 'r'); $saturs = fread($pass, 1024); talaak ka cerams izraksies PS nepretendeeju uz 100% perfektaako risinaajumu Link to comment Share on other sites More sharing options...
bubu Posted March 27, 2005 Report Share Posted March 27, 2005 Nu fread gan te ir nevietā toč! Tad jau labāk http://lv.php.net/fgets Link to comment Share on other sites More sharing options...
LorDRameX Posted March 27, 2005 Report Share Posted March 27, 2005 Nu fread gan te ir nevietā toč! Tad jau labāk http://lv.php.net/fgets 15644[/snapback] jep ta iet ka raksta no galvas un nepaluras kartiigi manuaalii ;) shitas tad ir labaaks risinaajums gan PS /me ielien sturitii nokauneeties Link to comment Share on other sites More sharing options...
rudzis Posted March 28, 2005 Author Report Share Posted March 28, 2005 Liels paldies, bubu :) Link to comment Share on other sites More sharing options...
rudzis Posted March 28, 2005 Author Report Share Posted March 28, 2005 (edited) Man radās vēl viens jautājums: Vai ir iespējams uzzināt, kurā passwords.txt rindiņā tika atrasts pareizais lietotājvārds un parole? Es mēģināju pirms cikla ielikt $id=0; un pēc tam ciklā $id++; , bet paliek nemainīgi 1. Edited March 28, 2005 by rudzis Link to comment Share on other sites More sharing options...
bubu Posted March 28, 2005 Report Share Posted March 28, 2005 Acīmredzot kautko nepareizi uzrakstīji. Rādi kodu. Vienkāršākajā gadījumā kautkam tādam taču ir jāstrādā: $id = 1; foreach (...) { if ($password = ...) { echo "Rinda ir: $id !"; } $id++; } Link to comment Share on other sites More sharing options...
rudzis Posted March 28, 2005 Author Report Share Posted March 28, 2005 (edited) Kods šāds: http://paste.php.lv/1786 ! Viss sanāca :) Edited March 28, 2005 by rudzis Link to comment Share on other sites More sharing options...
bubu Posted March 28, 2005 Report Share Posted March 28, 2005 Brīnums gan ka tev strādā. $id pēc cikla tak vienmēr būs vienāds ar to rindiņu skaitu, kuriem tas ifs izpildās, tātad rindiņu, kurās ir ievadītais logins un parole. Link to comment Share on other sites More sharing options...
rudzis Posted March 28, 2005 Author Report Share Posted March 28, 2005 (edited) bubu, reku jaunais, uzlabotais kods :) : <? error_reporting(0); $login = $_POST['login']; $password = $_POST['password']; $pass = array_map('trim', file("../passwords.txt")); $log = "0"; $id = 0; foreach($pass as $user) { $id++; $case = explode(":|:", $user); if($login == $case[0] && $password == $case[1]) { $userid = $id; $log = "1"; }} if($log == "1") { $pass_hash = md5($password); $cookie_data = "$userid:|:$pass_hash"; setcookie("stats_login", $cookie_data); echo '<script language="javascript">location="main.php"</script>'; } else { die("Ievadītie dati nav pareizi!"); } ?> Tikai nesaprotu, kaapeec kuukijs necepaas? Edited March 28, 2005 by rudzis Link to comment Share on other sites More sharing options...
bubu Posted March 28, 2005 Report Share Posted March 28, 2005 Ak dies, kas tev tur par perversijām kodā ;) Tik dīvaini tu tai ciklā tu tos datus meklē! Vai nav labāk šādi: <?php error_reporting(E_ALL); $login = $_POST['login']; $password = $_POST['password']; $pass = array_map('trim', file('../passwords.txt')); $id = 0; foreach($pass as $user) { $id++; $case = explode(':|:', $user); if ($login == $case[0] && $password == $case[1]) { $pass_hash = md5($password); $cookie_data = "$userid:|:$pass_hash"; setcookie('stats_login', $cookie_data); header('Location: main.php'); // tagad $id satur rindiņas numuru } } die("Ievadītie dati nav pareizi!"); ?> Link to comment Share on other sites More sharing options...
Recommended Posts