daGrevis Posted May 15, 2010 Report Share Posted May 15, 2010 Sveiki, Problēma rodas, kad lietotājs cenšas ielogoties ar nepareiziem datiem (t.i. username + password). Datu pareizību pārbauda funkcija combination()... function combination($ID, $password) { $query = mysql_query(' SELECT `ID` FROM `users` WHERE `ID`="' . $ID . '" AND `password`="' . $password . '" '); if(mysql_num_rows($query) === 1) { return true; } } Tad ir funkcija get__ID(), kas no ievadītā username pārveido to kā ID... function get__ID($username) { $query = mysql_query(' SELECT `ID` FROM `users` WHERE `username`="' . $username . '" '); return mysql_result($query, 0); } Un visbeidzot, fails, kurš, ja visam tiek "pass'ots" pāri - ielogo lietotāju sistēmā. =) Fragments... if(!combination(get__ID($_POST['username']), sha1($_POST['password']))) { $_SESSION['human_error'] = 'The username/password combination is invalid!'; redirect(ROOT . '/login.php'); } Problēma ir tad, kad combinācija neatbilst. Izmet šādu brīdinājumu... Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 10 in C:\xampp\htdocs\bliss\includes\functions.php on line 103 Īsti nevaru izdomāt kā lai novērš brīdinājumu. =/ Problēmas funkcijā get__ID(), jo nevar jau saņemt datus, ja tādu nav - tāpēc met brīdinājumu. Vai pareizas ceļš kā to atrisināt būtu '@'?? P.S. Par drošību lūdzu neteikt, zinu. =D Quote Link to comment Share on other sites More sharing options...
sandis_m Posted May 15, 2010 Report Share Posted May 15, 2010 (edited) if(mysql_num_rows($query) === 1) { mm.. kāpēc 3 = zīmes? un kāpēc tev tur viss ir tik sarežģīts... Edited May 15, 2010 by who_i_am Quote Link to comment Share on other sites More sharing options...
chizijs Posted May 15, 2010 Report Share Posted May 15, 2010 a varbūt pie get__ID($username); return mysql_num_rows($query); ? Quote Link to comment Share on other sites More sharing options...
briedis Posted May 15, 2010 Report Share Posted May 15, 2010 (edited) function get__ID($username){ $query = mysql_query('SELECT id FROM users HERE username="' . mysql_real_escape_string($username) . '"'); return mysql_num_rows($query) ? mysql_result($query, 0) : false; } Pēcāk: $id = get__ID($username); //Pieņemam, ka id > 0 if($id){ echo "Id ir: $id"; }else{ echo "Šāds id neeksistē"; //id ir false } Edited May 15, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
marcis Posted May 15, 2010 Report Share Posted May 15, 2010 (edited) mm.. kāpēc 3 = zīmes? http://fr.php.net/manual/en/language.operators.comparison.php http://lv.php.net/mysql_num_rows Return Values The number of rows in a result set on success or FALSE on failure. Edited May 15, 2010 by marcis Quote Link to comment Share on other sites More sharing options...
briedis Posted May 15, 2010 Report Share Posted May 15, 2010 http://fr.php.net/manual/en/language.operators.comparison.php http://lv.php.net/mysql_num_rows Varbūt jāpiemin, ka mysql_num_rows atgriezīs false tikai tad, ja padotais mainīgais nebūs resurss (mysql_query rezultāts), kas parasti ir tad, kad ir kļūda kvērijā. Normālā gadījumā atgrieztā vērtība būs >=0... Quote Link to comment Share on other sites More sharing options...
waplet Posted May 15, 2010 Report Share Posted May 15, 2010 A kur drošība? Quote Link to comment Share on other sites More sharing options...
mickys Posted May 15, 2010 Report Share Posted May 15, 2010 waplet, beidz kasīties. Varbūt cilvēks jau padod validētus datus Quote Link to comment Share on other sites More sharing options...
emsy Posted May 15, 2010 Report Share Posted May 15, 2010 (edited) if(!combination(get__ID($_POST['username']), sha1($_POST['password']))) { [...] Nope, nav validēti, funkcijās iet iekšā pa taisno no posta ;) Edited May 15, 2010 by emsy Quote Link to comment Share on other sites More sharing options...
mickys Posted May 16, 2010 Report Share Posted May 16, 2010 $_POST['username']=mysql_real_escape_string($_POST['username']); Varbūt tā, vietā, kuru mēs neredzam :D P.S. Jā, es apzinos, ka 99% tā nav, bet varbūt tomēr Quote Link to comment Share on other sites More sharing options...
daGrevis Posted May 16, 2010 Author Report Share Posted May 16, 2010 Paldies, briedis. =) Aizgāja man... =D Par drošību jau minēju. Heh =P who_i_am, man patīk, ka tur === nevis ==. =D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.