There is a code snippet in the php script. Tell me what is executed by this code? All these lines are in a separate ss.php file:

 <?php include 'settings.php'; $val = text($_GET['val'],$db); mysqli_query($db,"insert into nu3Dec (val) values ('$val')"); 

In settings.php , a connection to the database takes place and the script parameters are specified. The text () function there looks something like this (from the comment):

 function text( $text, $db) { $text = mysqli_real_escape_string($db, $text); $text = htmlspecialchars($text, ENT_QUOTES); if( get_magic_quotes_gpc ()) { $text = stripslashes($text); } $text = trim($text); return $text; } 
  • 2
    Please find the definition of the text () function and attach it to the question. - cheops

2 answers 2

 include 'settings.php'; // подключение модуля settings.php $val = text($_GET['val'],$db); // $_GET['val'] - смотрим url запроса к скрипту и берем из него значение val // пример, http://site.ru/index.php?val=5 // в данном случае возьмем $_GET['val'] вернется 5 // если val нету будет null // ту переменную которую получили и переменную $db передаем в функцию text() // похоже, что $db это класс работы с базой данных в settings.php // а text(), похоже тупо заносит в базу данных, параметр $_GET['val'] mysqli_query($db,"insert into nu3Dec (val) values ('$val')"); // ну тут просто, выполняется sql запрос к базе данных вида // "insert into nu3Dec (val) values ('$val')" // вставляется в таблицу nu3Dec тот самый val 

PS Do not forget to screen requests, because attackers can insert injections into the database.

  • one
    Thank you for the detailed response. - Karlos Derga
  • @Karlos Derga, not at all :) - akula

The fragment processes the GET parameter val , which comes in via the query string, and inserts a new entry into the database in the nu3Dec table with the filtered text() function with the GET parameter val.

  • Thank! Hope this is not a malicious code. - Karlos Derga
  • four
    Maybe a malicious one - you have to make sure what the unknown text() function does - all of a sudden, is it constructing a SQL injection? :) - Sergiks
  • I would love to do it, but not good at php at all. Thank you for the exhaustive information. - Karlos Derga
  • one
    Something like this: $ text = mysqli_real_escape_string ($ db, $ text); $ text = htmlspecialchars ($ text, ENT_QUOTES); if (get_magic_quotes_gpc ()) {$ text = stripslashes ($ text);} $ text = trim ($ text); return $ text; - Karlos Derga