今天看书中做留言板,看到了这么两个函数
string addslashes ( string str )
对于这个函数大家可以查手册,上面是中文,说的很详细的.
自己也就不多说什么了,主要介绍一下下面这个函数.
int get_magic_quotes_gpc ( void )

手册中string addslashes ( string str )介绍的时候有这样一句话说明了get_magic_quotes_gpc的用法以及作用
默认情况下,PHP 指令 magic_quotes_gpcon,它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。


其实这个函数就是判断有PHP有没有自动调用addslashes 这个函数,
下面是例子,其实也是从手册上弄下来的,传过来就为自己看着方便,因为自己记性不好..


见笑:
< html >
    <!--以POST方式传过去一个带有单引号的字符串 -->
     < body >
          < form action ="first.php" method ="post" >
               < input type ="text" name ="lastname" value ="Simao'pig" >
               < input type ="submit" value ="提交" >
          </form>
     </body>    
    
</html>

<?php
echo get_magic_quotes_gpc();         // 很不好意思,我的这个是0
echo $_POST['lastname'];             //
Simao'pig
echo addslashes($_POST['lastname']); // Simao\'pig

if (!get_magic_quotes_gpc()) {
    
$lastname = addslashes($_POST['lastname']);
} else {
    
$lastname = $_POST['lastname'];
}

echo
$lastname; //
Simao\'pig
$sql = "INSERT INTO lastnames (lastname) VALUES ('$lastname')";
?>