briedis Posted July 19, 2012 Report Share Posted July 19, 2012 SQL injekcijas un kā izsargāties: http://lmgtfy.com/?q=php+sql+injections Lai sāktos ar 1, nevis 0? Papēti sīkāk, kas ir tas for() cikls, un kādi parametri viņam tiek padoti. http://php.net/manual/en/control-structures.for.php Link to comment Share on other sites More sharing options...
Amerika Posted July 19, 2012 Author Report Share Posted July 19, 2012 $limits = 10; $data3 = mysql_query("SELECT COUNT(*) FROM news_comments WHERE news_id = '$_GET[n]'"); $row3 = mysql_fetch_array($data3); $lpp = $_GET['lpp']; $ceil = ceil($row3['COUNT(*)']/$limits); $OFFSET = $lpp*$limits-$limits; $data4 = mysql_query("SELECT * FROM news_comments WHERE news_id = '$_GET[n]' LIMIT $OFFSET,$limits") or die(mysql_error()); $sql_inj = mysql_real_escape_string($_GET[n]); Cik sapratu tad $sql_inj rindiņa tiek galā ar injekciju. Problēma ar for. $page = 1; for( $adrpage = 1; $adrpage < $ceil; $adrpage++) { echo '<a href="', '?n=' , $_GET[n] , '&lpp=' , $adrpage ,'">' . $page . '</a>'; $page++; } Ieliekot $adrpage = 1; sākas pirmais ieraksts ar 1, bet nav vairs 2 lapušu, tādēļ ka for tāpat sāk ar 0 skaitīt lapuses. Php.net neatradu to kā nomainīt, ka sākas viss ar 1, bet tikai to ka viņš turpinās tālāko funkciju ar 1. Link to comment Share on other sites More sharing options...
briedis Posted July 19, 2012 Report Share Posted July 19, 2012 Kāda jēga no tā $sql_inj mainīgā? Tev jāsaprot kā darboties ar mainīgjaiem - $drosha_vertiba = mysql_real_..($nedrosha_vertiba_kas_nak_no_lietotaja); mysql_query("SELECT * FROM blabla WHERE bla = $drosha_vertiba "; Bet tu uzrakstīji: mysql_query("SELECT .. WHERE bla = $nedrosha_vertiba"); $pilnigs_randoms_kas_nekur_talak_netiek_izmantots = mysql_real_esc...($nedrosha_vertiba) Izprati starpību? Link to comment Share on other sites More sharing options...
Amerika Posted July 19, 2012 Author Report Share Posted July 19, 2012 (edited) http://www.tizag.com...l-injection.php Mazliet ne tā uzrakstīju. Pēc šī varianta skatījos un tad ir jābūt šādi? $limits = 10; $data3 = mysql_query("SELECT COUNT(*) FROM news_comments WHERE news_id = '$_GET[n]'"); $row3 = mysql_fetch_array($data3); $lpp = $_GET['lpp']; $ceil = ceil($row3['COUNT(*)']/$limits); $OFFSET = $lpp*$limits-$limits; $data4 = mysql_query("SELECT * FROM news_comments WHERE news_id = '$_GET[n]' LIMIT $OFFSET,$limits") or die(mysql_error()); $_GET[n] = mysql_real_escape_string($_GET[n]); Edited July 19, 2012 by Amerika Link to comment Share on other sites More sharing options...
briedis Posted July 19, 2012 Report Share Posted July 19, 2012 iedomājies ka mysql_real_escape_string ir prezervatīvs un mysql_query sekss.. kādēļ tu prezervatīvu gribi uzvilkt pēc seksa? :D ceru ka sapratīsi šo piemēru.. Hahaha, šitais labs salīdzinājums :D Link to comment Share on other sites More sharing options...
Amerika Posted July 19, 2012 Author Report Share Posted July 19, 2012 (edited) $_GET[n] = mysql_real_escape_string($_GET[n]); $query = "SELECT * FROM news_comments WHERE news_id = '$_GET[n]' LIMIT $OFFSET,$limits"; $execute = mysql_query ($query); Šādi ? :) Edited July 19, 2012 by Amerika Link to comment Share on other sites More sharing options...
briedis Posted July 19, 2012 Report Share Posted July 19, 2012 $_GET[n] = mysql_real_escape_string($_GET[n]); $query = "SELECT * FROM news_comments WHERE news_id = '$_GET[n]' LIMIT $OFFSET,$limits"; $execute = mysql_query ($query); Šādi ? :) Jau labāk, bet labāk neaiztiec/nemaini $_GET mainīgos $news_id = mysql_real_escape_string($_GET['n']); Kā arī, kad piekļūst indeksam, tā tekstuālo vērtību vienmēr liec pēdiņās! $_GET[blabla] <-- SLIKTI! $_GET['blabla'] LABI! Link to comment Share on other sites More sharing options...
Amerika Posted July 19, 2012 Author Report Share Posted July 19, 2012 bet labāk neaiztiec/nemaini $_GET mainīgos Ko tu ar to domā? Neizmantot skriptos? Link to comment Share on other sites More sharing options...
briedis Posted July 19, 2012 Report Share Posted July 19, 2012 Nē, es domāju tā, ka tu izmanto tikai lai iegūtu vērtību, nevis tur ierakstītu. Tas pats attiecas uz $_POST masīvu Pareizs pielietojums (tikai nolasīšana): $mainigais = $_GET['mainigais']; if($_GET['kkas']){ .. Nepareizs (ierakstīšana): $_GET['kkas'] = kautkascits Link to comment Share on other sites More sharing options...
Amerika Posted July 19, 2012 Author Report Share Posted July 19, 2012 (edited) Kā arī, kad piekļūst indeksam, tā tekstuālo vērtību vienmēr liec pēdiņās! $_GET[blabla] <-- SLIKTI! $_GET['blabla'] LABI! Mainīju visu kodu bet neiet pie indeksa. $_GET['n'] = mysql_real_escape_string($_GET['n']); $query = "SELECT * FROM news_comments WHERE news_id = '$_GET[n]' LIMIT $OFFSET,$limits"; $data4 = mysql_query ($query) or die(mysql_error()); Ja es mainu $_GET[n] uz $_GET['n'], kas atrodās $query tad skripts crasho, balts ekrāns. Nav domāts tā vai kā? Bet atradu risinājumu '".$_GET['n']."' Tā ir pareizi rakstīt indeksā, jo iet? Kā arī prasu par for atkal. $page = 1; for( $adrpage = 0; $adrpage < $ceil; $adrpage++) { echo '<a href="', '?n=' , $_GET['n'] , '&lpp=' , $adrpage ,'">' . $page . '</a>'; $page++; } Ieliekot $adrpage = 1; sākas pirmais ieraksts ar 1, bet nav vairs 2 lapušu, tādēļ ka for tāpat sāk ar 0 skaitīt lapuses. Php.net neatradu to kā nomainīt, ka sākas viss ar 1, bet tikai to ka viņš turpinās tālāko funkciju ar 1. Edited July 20, 2012 by Amerika Link to comment Share on other sites More sharing options...
briedis Posted July 20, 2012 Report Share Posted July 20, 2012 Nu kamōn... $news_id = mysql_real_escape_string($_GET['n']); $query = "SELECT * FROM news_comments WHERE news_id = '$news_id' LIMIT $OFFSET,$limits"; $data4 = mysql_query ($query) or die(mysql_error()); Link to comment Share on other sites More sharing options...
Amerika Posted July 20, 2012 Author Report Share Posted July 20, 2012 Nu kamōn... $news_id = mysql_real_escape_string($_GET['n']); $query = "SELECT * FROM news_comments WHERE news_id = '$news_id' LIMIT $OFFSET,$limits"; $data4 = mysql_query ($query) or die(mysql_error()); izmantoju šo variantu '".$_GET['n']."' ar ko viss iet. Kā arī atrisināju for problēmu $adrpage < $ceil vietā ieliku $adrpage <= $ceil Paldies par atsaucību briedi. :) Link to comment Share on other sites More sharing options...
y2ok Posted July 20, 2012 Report Share Posted July 20, 2012 Kāpēc, Tu baidies definēt jaunus mainīgos? Link to comment Share on other sites More sharing options...
Amerika Posted July 20, 2012 Author Report Share Posted July 20, 2012 (edited) Kāpēc, Tu baidies definēt jaunus mainīgos? *Nav garumzimes paslaik. Varetu pateikt ko tu ar to doma un neatceros, ka butu baidijies kautko rakstit. :) Edited July 20, 2012 by Amerika Link to comment Share on other sites More sharing options...
y2ok Posted July 20, 2012 Report Share Posted July 20, 2012 (edited) $_GET['n'] = mysql_real_escape_string($_GET['n']); vietā kāpec tu neizmanto - $variable = mysql_real_escape_string($_GET['n']); Edited July 20, 2012 by y2ok Link to comment Share on other sites More sharing options...
Recommended Posts