mjc66 Posted June 20, 2007 Report Share Posted June 20, 2007 Вот код моего поискового скрипта: <?php//connection to MySQL$db_host = "localhost";$db_user = "login";$db_password = "password";$db_name = "my_db";$connection = mysql_connect ($db_host, $db_user, $db_password) or die ('error connection');mysql_select_db($db_name, $connection);//variables@$id =$_GET['id'];@$name =$_GET['name'];@$page =$_GET['page'];@$group_production =$_GET['group_production'];//chekboxesif ( empty($name ) ){// не заполнено полеdie("<div class='search' align='center'> <font color='#CC0000'><b>Необходимо заполнить поле поиска!</b></font></div>");}if (isset($id)) {$srch='id';} //id - имя столбца в таблицеif (isset($name)) { $srch='name';} //name - имя столбца в таблице if (isset($page)) { $srch='page';} //page - имя столбца в таблице if (isset($group_production)) { $srch='group_production';} //group_production - имя столбца в таблице @$query = "SELECT * FROM tovary WHERE $srch like '%$name%' "; $result = mysql_query($query) or die('Ошибка запроса'); if ( mysql_num_rows($result) == 0 ) { print("<div class='search' align='center'> <font color='#CC0000'><b>По вашему запросу ничего не найдено! Попробуйте изменить форму поиска.</b></font></div>"); } else { print("<table border='1' cellspacing='1' cellpadding='1' class='search'><caption align=top class='search'>Результат поиска:</caption><tr><td width='35%' class='search_top' align='center'><b>Наименование товара</b></td><td width='20%' class='search_top' align='center'><b>Страница в каталоге</b></td><td width='30%' class='search_top' align='center'><b>Группа товаров</b></td></tr>"); // Переменная i следит чередование цвета $i = 0; while($t = @mysql_fetch_array($result)) { $i++; $class = ( $i % 2 == 0 ) ? "odd" : "even"; print(' <style> .odd{background:99FFCC} .even{background:FFFFCC} </style> <tr class="'.$class.'"> <td width="35%" class="search"><font color="#000000">'.$t[name].'</font></td> <td width="20%" class="search"><a class="1" href="'.$t .'?id='.$t[id].'">Найти на странице</a></font></td> <td width="30%" class="search"><font color="#000000">'.$t[group_production].'</font></td> </tr>'); } print("</table>"); }?> Сам я в этом ничего не волоку, но те кто его видел, как-то пространно намекали на уязвимость кода (или БД???). Вобщем если такая проблема действительно есть, то большая просьба указать в каком месте и пути ее устранения. Заранее благодарю. Link to comment Share on other sites More sharing options...
Darhazer Posted June 20, 2007 Report Share Posted June 20, 2007 это верно. Вы не проверяете параметер $name Надо @$name =$_GET['name']; Заменить на @$name = mysql_escape_string($_GET['name']); Link to comment Share on other sites More sharing options...
mjc66 Posted June 20, 2007 Author Report Share Posted June 20, 2007 это верно. Вы не проверяете параметер $name Надо @$name =$_GET['name']; Заменить на @$name = mysql_escape_string($_GET['name']); Заменил как ты сказал, верно ли будет в самом запросе изменить строку @$query = "SELECT * FROM tovary WHERE $srch like '%$name%' "; на строку @$query = "SELECT * FROM tovary WHERE $srch like '%".mysql_escape_string(addslashes($name))."%' "; или при ипользовании 1-го варианта это становится лишним? Link to comment Share on other sites More sharing options...
Darhazer Posted June 20, 2007 Report Share Posted June 20, 2007 Можно и в запросе конечно. Только если пользуеш мysql_escape_string, addslashes уже не нужни.... Даже нужно поменять на mysql_real_escape_string, а если не уверен что он поддерживаеться: if( ! function_exists ( 'mysql_real_escape_string' ) ){function mysql_real_escape_string( $value ){ return addslashes($value); }} Link to comment Share on other sites More sharing options...
mjc66 Posted June 20, 2007 Author Report Share Posted June 20, 2007 Можно и в запросе конечно. Только если пользуеш мysql_escape_string, addslashes уже не нужни.... Даже нужно поменять на mysql_real_escape_string, а если не уверен что он поддерживаеться: if( ! function_exists ( 'mysql_real_escape_string' ) ){function mysql_real_escape_string( $value ){ return addslashes($value); }} //variables@$id =$_GET['id'];@$name = mysql_real_escape_string($_GET['name']);if( ! function_exists ( 'mysql_real_escape_string' ) ){function mysql_real_escape_string( $value ){ return addslashes($value); }}@$page =$_GET['page'];@$group_production =$_GET['group_production']; правильно? Link to comment Share on other sites More sharing options...
Darhazer Posted June 20, 2007 Report Share Posted June 20, 2007 Почти... if( ! function_exists ( 'mysql_real_escape_string' ) ){function mysql_real_escape_string( $value ){ return addslashes($value); }}//variables@$id =$_GET['id'];@$name = mysql_real_escape_string($_GET['name']);@$page =$_GET['page'];@$group_production =$_GET['group_production']; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now