johanes Posted August 9, 2004 Report Share Posted August 9, 2004 (edited) Ir divi mainīgie, kuri glabājas txt failā. Ievadot abus mainīgos, nospiežot pogu submit, vajag lai tiktu pārbaudīt txt failā vai mainīgie sakrīt Skatījos pa forumu uzgāju tikai http://php.lv/f/index.php?showtopic=345 šo topiku, bet tas īsti neder, jo failā ir tikai 1 parole. Piem. txt faila ieraksti: janins::suns juris::lacis peteri::zilonis Izvadot mainiigos $a un $b, pārbaudot txt jāatrod ka $a == $b :( :( :( Edited August 9, 2004 by johanes Link to comment Share on other sites More sharing options...
Venom Posted August 10, 2004 Report Share Posted August 10, 2004 (edited) cik saprotu, $a ir "juris", $b ir "lacis", aka $a==username, $b==pasword? if (isset($_POST['a'],$_POST['b'])) { $usr_pwd_combo=file('paroles.txt'); if (!in_array($_POST['a'].'::'.$_POST['b']."\n",$usr_pwd_combo)) { echo 'no such usr/pwd combination'; exit; } } Edited August 10, 2004 by Venom Link to comment Share on other sites More sharing options...
bubu Posted August 10, 2004 Report Share Posted August 10, 2004 Ņjā, ūbersarežģīts algoritms... Link to comment Share on other sites More sharing options...
johanes Posted August 10, 2004 Author Report Share Posted August 10, 2004 Šis algoritms nedarbojas. Kā būtu ar funkcija array_search()!!!! Link to comment Share on other sites More sharing options...
bubu Posted August 10, 2004 Report Share Posted August 10, 2004 Nu nu, nestāsti, ka nestrādā! Noteikti strādā, vienīgi tās strādāšanas piedabūšanas sarežģītums tev droši vien ir tieši proporcionāls roku izliekuma leņķim. Un ja jau Venom'a dotais nestrādā, un tu saki, ka derētu lietot array_search, tad tik uz priekšu! Mēģini, eksperimentē, un galvenais lasi dokumentāciju! :D Link to comment Share on other sites More sharing options...
johanes Posted August 11, 2004 Author Report Share Posted August 11, 2004 Nu tipa man ir tā par.txt lacis::maja suns::govs kakis::koks login.php <? header("Content-type:text/vnd.wap.wml;charset=utf-8"); print "<?xml version=\"1.0\"?>\n"; print "<wml>\n"; include 'template.php'; print "<card title=\"Login\">\n"; echo "<p>Niks:</p> <p align=\"center\"> <input name=\"name\" format=\"*m\" maxlength=\"12\" method=\"post\"/><br/>"; echo "<p>Parole:</p> <p align=\"center\"> <input name=\"par\" type=\"password\" maxlength=\"12\" method=\"post\"/><br/> <anchor>Autorizacijat<go href=\"login1.php?name=$(name)&par=$(par)\" type=\"submit\"> </go> </anchor>\n"; </card></wml>\n"; ?> un login1.php <? header("Content-type:text/vnd.wap.wml;charset=utf-8"); print "<?xml version=\"1.0\"?>\n"; print "<wml>\n"; echo '<card>'; if (isset($_POST['name'],$_POST['par'])) { $usr_pwd_combo=file('par.txt'); if (!in_array($_POST['name'].'::'.$_POST['par']."\n",$usr_pwd_combo)) { echo '<p>no such usr/pwd combination</p>'; exit; } } echo '</card></wml>'; ?> Tas algoritms ir pāk sarežģīts. Varbūt kāds var palīdzēt, lūdzu Link to comment Share on other sites More sharing options...
bubu Posted August 11, 2004 Report Share Posted August 11, 2004 (edited) Īsti nepārzinu WML, bet vai tur nav jābūt formas elementam? Tur tiešām pie katra formas input elementa jānorāda method="post"? Jā, un tev ļoti patīk pēdiņas escapot visu laiku, vai kā? Tak raksti šādi: login.php <?php header("Content-type:text/vnd.wap.wml;charset=utf-8"); echo '<?xml version="1.0"?><wml>'; include ('template.php'); echo '<card title="Login">'; echo '<p>Niks:</p>'; echo '<input name="name" format="*m" maxlength="12" method="post"/><br/>'; echo '<p>Parole:</p>'; echo '<input name="par" type="password" maxlength="12" method="post"/><br/>'; echo '<anchor>Autorizacijat<go href="login1.php?name=$(name)&par=$(par)" type="submit">'; echo '</go></anchor>'; echo '</card></wml>'; ?> Vai tagad kods neliekas 'tīrāks'? Un pie tam, vai šis: login1.php?name=$(name)&par=$(par) nenorāda to, ka parametri tiek nodoti caur $_GET nevis $_POST? Paņem tak login1.php skriptā izdrukā (print_r($_GET) un print_r($_POST)) visus pieprasījuma masīva elementus un paskaties vai tiešām name un par ir tādi kādi vajag! Un izdrukār arī $usr_pwd_combo masīvu un apskaties, vai tur iekšā ir tas kas vajadzīgs. Edited August 11, 2004 by bubu Link to comment Share on other sites More sharing options...
johanes Posted August 11, 2004 Author Report Share Posted August 11, 2004 Nu es nodevu mainīgos ar post echo '<postfield name="name" value="$(name)"/>'; echo '<postfield name="par" value="$(par)"/>'; login.php <? header("Content-type:text/vnd.wap.wml;charset=utf-8"); echo '"<?xml version=\"1.0\"?>\n'; echo '<wml>\n'; echo '<card>'; if (isset($_POST['name'],$_POST['par'])) { $usr_pwd_combo=file('par.txt'); if (!in_array($_POST['name'].'::'.$_POST['par']."\n",$usr_pwd_combo)) { echo '<p>no such usr/pwd combination</p>'; exit; } } print_r($_POST); echo'<p>$usr_pwd_combo</p>'; echo '</card></wml>'; ?> man izdrukā tikai Array ( ) Link to comment Share on other sites More sharing options...
bubu Posted August 11, 2004 Report Share Posted August 11, 2004 Tas nozīmē, ka nepareizi padod mainīgos no WML lapas, ja jau tukšs masīvs sanāk. Kā jābūt pareizi, es nezinu. Neesmu WML nekad veidojis. Link to comment Share on other sites More sharing options...
johanes Posted August 12, 2004 Author Report Share Posted August 12, 2004 (edited) Pārtaisot skriptu html valodā izdrukā : Array ( [name]=> maja [par] => govs [submit] => Pieslegties ) no such usr/pwd combination Paši faili ir: login2.php pats skripts šeit <? ... ?> login3.php pats skripts šeit <? ... ?> txt failā ir šādi ieraksti: kaza::parbaudemaja::govs kakis::suns Palīdziet lūdzu, man tas ir ļoti svarīga lieta :( Edited August 12, 2004 by johanes Link to comment Share on other sites More sharing options...
bubu Posted August 13, 2004 Report Share Posted August 13, 2004 login3 pārtaisi šādi: <?php echo '<html><head></head><body>'; if (isset($_POST['name'],$_POST['par'])) { $usr_pwd_combo = array_map('trim', file('reg.txt')); if (!in_array($_POST['name'].'::'.$_POST['par'],$usr_pwd_combo)) { echo '<p>no such usr/pwd combination</p>'; exit; } } echo "<p>$usr_pwd_combo</p>"; echo '</body></html>'; ?> Link to comment Share on other sites More sharing options...
johanes Posted August 13, 2004 Author Report Share Posted August 13, 2004 Paldies tev bubu, tagad viss ir ok :) Link to comment Share on other sites More sharing options...
Recommended Posts