Специални символи

eddyy93

Registered
В момента забелязах нещо което ме учуди доста ...

PHP:
<?php
if(isset($_POST['submit'])) {
$name=htmlentities($_POST['ime']);
echo $name;
}
?>
<form action="test.php" method="post">
    <input type="text" name="ime" />
    <input type="password" name="pass" />
    <input type="submit" name="submit" value="ВЛЕЗ" />
</form>

При този код когато давам да ми отпечата името което съм въвел тези htmlentites или htmlspecialchars изобщо не работят!

Но ако кода е написан така работят:

PHP:
<?php
if(isset($_POST['submit'])) {
$name=htmlentities($_POST['ime']);
echo htmlentities($name);
}
?>
<form action="test.php" method="post">
    <input type="text" name="ime" />
    <input type="password" name="pass" />
    <input type="submit" name="submit" value="ВЛЕЗ" />
</form>
 
Сега тествах и при addslashes . При него няма такъв проблем.

PHP:
<?php
if(isset($_POST['submit'])) {
$name=addslashes($_POST['ime']);
echo $name;
}
?>
<form action="test.php" method="post">
    <input type="text" name="ime" />
    <input type="password" name="pass" />
    <input type="submit" name="submit" value="ВЛЕЗ" />
</form>
 
Ам ти !@№$?§ ли искаш да забраниш? Това се прави с регулярен израз...
 
ето ти мойте функции който съм си написал

function sql($value) {
// Use this function on all those values where you want to check for both sql injection and cross site scripting
//Trim the value
$value = trim($value);

// Stripslashes
if (get_magic_quotes_gpc ()) {
$value = stripslashes($value);
}

// Convert all <, > etc. to normal html and then strip these
$value = strtr($value, array_flip(get_html_translation_table(HTML_ENTITIES)));

// Strip HTML Tags
$value = strip_tags($value);

// Quote the value
$value = mysql_real_escape_string($value);
$value = htmlspecialchars($value);
return $value;
}

function text($text = '') {
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
$ret = substr($ret, 1);
return $ret;
}

няма да имаш проблеми
 

Back
Горе