dimitrius
Новичок
dimitrius
а вы уверены, что оно вам надо. с основами у вас плохо, особенно для создателя магазина незнание безопасного программирования - смерть. и самое паршивое, что это указывает на то, что вы поленились даже одну толстую книгу прочитать.
работа программиста не самая лёгкая, а зарплата не самая высокая, с вашим экономическим опытом можно найти что-то получше.
а вообще, это конечно возможно, как правило зарплата слабо коррелируется с реальными знаниями. главное умение себя хорошо продавать, что с экономическим образованием получается гораздо лучше.
PHP:
<?php
class String_Safety{
private $inputString;
private $handledString;
private $inspectionResult;
private $MAX_LENGHT;
const SUBSTITUTE_CHAR = '';
public function __construct($inputString = ""){
$this ->setStringForHendling($inputString);
$this ->setHandledString("Handling was not carried out");
$this ->inspectionResult = "Inspection wasn't conducted";
$this ->MAX_LENGHT = 100;
}
public function setStringForHendling($inputString){
$this ->inputString = $inputString;
}
public function setMAX_LENGHT($inputInteger){
if(intval($inputInteger) === $inputInteger){
$this ->MAX_LENGHT = intval($inputInteger);
}
}
private function setHandledString($handledString){
$this ->handledString = $handledString;
}
public function getInputString(){
return $this ->inputString;
}
public function getHandledString(){
return $this ->handledString;
}
public function getInspectionResult(){
return $this ->inspectionResult;
}
public function inspectAndReplaceNotDomainSymb(){
$forbiddenChars = "/[^-._0-9a-zA-Z]/";
$this ->inspectAndReplace($forbiddenChars, String_Safety::SUBSTITUTE_CHAR);
}
public function inspectAndReplaceNotLetterAndNumSymb(){
$forbiddenChars = "/[^0-9a-zA-Z]/";
$this ->inspectAndReplace($forbiddenChars, String_Safety::SUBSTITUTE_CHAR);
}
public function inspectAndMakeHtmlEntities(){
$inputString = $this ->getInputString();
$handledString = htmlentities($inputString, ENT_QUOTES, "UTF-8");
$this ->setHandledString($handledString);
$this ->stringInspection();
}
public function inspectAndProtectMysqlQuery($connectLink){
$inputString = $this ->getInputString();
$forbiddenChars = "/\s+/mu";
$substitute = ' ';
$handledString = $this ->replaceForbiddenChar($forbiddenChars, $substitute, $inputString);
$handledString = mysqli_real_escape_string($connectLink, $handledString);
$this ->setHandledString($handledString);
$this ->stringInspection();
}
private function inspectAndReplace($forbiddenChars,$substitute){
$stringWhereNeedReplace = $this ->getInputString();
$handledString = $this ->replaceForbiddenChar($forbiddenChars, $substitute,
$stringWhereNeedReplace);
$this ->setHandledString($handledString);
$this ->stringInspection();
}
private function stringInspection(){
$stringsAreSame = (strcmp($this ->inputString, $this ->handledString) === 0);
$stringLenghtAreCorrect = (strlen($this ->inputString) <= $this ->MAX_LENGHT);
if($stringsAreSame && $stringLenghtAreCorrect){
$this ->inspectionResult = TRUE;
}
else {
$this ->inspectionResult = FALSE;
}
}
private function replaceForbiddenChar($forbiddenChars, $substitute, $inputString){
$safeString = preg_replace ($forbiddenChars,
$substitute,
$inputString);
return $safeString;
}
function __destruct(){
unset($this ->inputString);
unset($this ->handledString);
unset($this ->inspectionResult);
unset($this ->MAX_LENGHT);
}
}
?>