zoukankan      html  css  js  c++  java
  • PHP

    Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime()

    https://blog.csdn.net/jiulongls/article/details/85611134

    环境搭建

    Window7+Apache24+PHP7.2
    
    Apache24配置
    LoadModule php7_module "D:/SoftWare/php-7.2.21-Win32-VC15-x64/php7apache2_4.dll"
    PHPIniDir "D:/SoftWare/php-7.2.21-Win32-VC15-x64/"
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .html
    AddType application/pdf .pdf
    LoadModule php7_module modules/libphp7.so
    DirectoryIndex index.php index.htm index.html

    数据类型

    Boolean 布尔类型
    Integer 整型
    Float 浮点型
    String 字符串
    Array 数组
    Object 对象
    Resource 资源类型
    NULL
    Callback / Callable 类型

    数据库操作 - 数据库操作

    连接
    $con=new mysqli($host,$user,$password,$dbName); $con=mysqli_connect("localhost","root","root","test");

    连接报错处理

    if ($link->connect_error) {
    die("连接失败:" . $link->connect_error);
    }

    if (mysqli_connect_errno($con))
    {
    echo "连接 MySQL 失败: " . mysqli_connect_error();
    }

    增删改查

    mysqli_fetch_assoc 获取首行数据
    $row = mysqli_fetch_assoc($result);
    echo $row['number1'];
    echo $row['id'];
    echo $row['number2'];"

    mysqli_fetch_row

    mysqli_fetch_array

    mysqli_fetch_assoc

    取多行数据
    while($row=mysqli_fetch_assoc($result)){
    $result_set[] = $row['Profile'];
    }

    插入
    $sql = ""insert into tt values('$txt')"";
    $result = mysqli_query($con,$sql);"

    对insert结果判断
    if($result){
    echo ""1"";
    }else{
    echo mysqli_error();
    }

    数据库操作 - 连接封装

    <?php
    class db
    {
        public $host = "localhost";
        public $username = "root";
        public $password = "root";
        public $dbname = "test";
    
        public function Query($sql,$type=1)
        {
            $db = new mysqli($this->host,$this->username,$this->password,$this->dbname);
            $r = $db->query($sql);
            if($type == "1")
            {
                return $r->fetch_all();
            }
            else
            {
                return $r;
            }
        }
    
    }
    
    ?>
    
    使用(按列遍历数据,此处为三列数据):
    <?php
    include("db.class.php");
    $db=new db();
    
    $sql = "select * from user";
    $arr=$db->Query($sql);
    
    foreach($arr as $v)
    {
        echo "
        <tr>
            <td>{$v[0]}</td>
            <td>{$v[1]}</td>
            <td>{$v[2]}</td>
        </tr>
        ";
    }
    
    ?>
    View Code

    文件处理 - 写入数据

    file_put_contents('test.txt','aas');

    文件处理 - 打开文件

    fopen

    写入 xml 文件 

    <?php
    /**
    * function:使用字符串方式写XML文件
    * author:JetWu
    * date:2016.12.03
    **/
    $mysqli = mysqli_connect('localhost', 'root', 'root', 'test');
    if(mysqli_connect_errno()) 
     die('database connect fail:' . mysqli_connect_error());
     
    $sql = 'select * from tt order by starttime';
    $res = mysqli_query($mysqli, $sql);
    $study = array();
    while($row = mysqli_fetch_array($res)) {
        $study[] = $row;
    }
    //XML标签配置
    $xmlTag = array(
        'starttime',
        'endtime',
        'school'
    );
     
    $str = "<studentcareer>
    ";
    foreach($study as $v) {
        $str .= "	<period>
    ";
        foreach($xmlTag as $x) {
            $str .= "		<".$x.">" . $v[$x] . "</".$x.">
    ";
          
        }
        $str .= "	</period>
    ";
    }
    $str .= '</studentcareer>';
     
    $file = './write_str.xml';
    file_put_contents($file, $str);
    View Code

    XML 字符串载入对象

    $data = simplexml_load_string($xml);  -返回对象

    Cookie处理

    cookie(setcookie(name,value,expire,path,domain,secure))        服务端创建,客户端保存(浏览器缓存中-未设置过期时间;硬盘-设置了过期时间),有长度限制    
    setcookie("unameck",$user);    cookie创建    "创建一个数组 cookie:
    <?php
    setcookie(""cookie[three]"",""cookiethree"");
    setcookie(""cookie[two]"",""cookietwo"");
    setcookie(""cookie[one]"",""cookieone"");
    // print cookies (after reloading page)
    if (isset($_COOKIE[""cookie""]))
    {
    foreach ($_COOKIE[""cookie""] as $name => $value)
    {
    echo ""$name : $value <br />"";
    }
    }
    ?>"    
    echo $_COOKIE['unameck'];            
    setcookie ("TestCookie", "", time() - 3600);    cookie删除        
    变量            
    empty($user) or empty($pwd)    非空判断        
    echo '<br/>';    换行        
    View Code

    Token处理

    token    "cookie+token -》安全保证
    防cookie被串改(cookie欺骗、cookie劫持)
    避开同源策略。
    避免 CSRF 攻击。
    无状态的、可以在多个服务间共享。"    
    1.防止表单重复提交        
    2.anti csrf攻击(跨站点请求伪造)        

    Session处理

    session    "选择使用cookie而不是用session的原因:在一些大型的应用中,服务器可能不止一台,所以,无法知道,用户注册的session保存在哪台服务器上。
    但是,记住一点就是,session可以保存在memcached中。这里需要修改PHP.INI配置文件"    
    函数        
    eval        
    eval("echo 'hello world';");    相当于echo str / 这里str后面需要有分号    
    if(!filter_var($email, FILTER_VALIDATE_EMAIL))    验证电子邮件地址    
    停止脚本        
    die('str')/exit(0)        
    View Code

    转义函数

    mysql_real_escape_string()   受影响字符:x00 
     
       '  "  x1a   --成功,则该函数返回被转义的字符串。如果失败,则返回 false
    
    magic_quotes_gpc()   magic_quotes_gpc=On(php<6.0的版本默认为on)的情况下,如果输入的数据有单引号(’)、双引号(”)、反斜线()与 NUL(NULL 字符)等字符都会被加上反斜线
    
    stripslashes()  --添加/删除反斜线
    
    addslashes()  #get/post/cookie中的(’)、双引号(”)、反斜线()与 NUL(NULL 字符)等字符都会被加上斜线 ---斜线不插入到数据库中(可读取做二次渗透)

    htmlspecialchars() #将特殊字符用引用实体替换,如<script>alert('xss')</script>通过htmlspecialchars()过滤后为&lt;script&gt;alert(&#039;xss&#039;)&lt;/script&gt

    set_magic_quotes_runtime() #用来设置php.ini文件中的magic_quotes_runtime值,当遇到反斜杆()、单引号(')、双引号(")这样一些的字符定入到数据库里,又不想被过滤掉,使用这个函数,将会自动加上一个反斜杆(),保护系统和数据库的安全。0和false表示关闭本功能,1和true表示打开本功能。当magic_quotes_runtime打开时,所有外部引入的数据库资料或者文件等都会自动转为含有反斜线溢出的资料(HP5.3后此特性(set_magic_quotes_runtime())已经关闭,而且在PHP6中已经完全移除此特性)

    文件包含函数

    allow_url_fopen
    allow_url_include
    都为ON —》则文件包含函数是可以加载远程文件的 PHP5.2开始allow_url_include就默认为Off,而allow_url_fopen一直是On

    字符处理函数

    把所有字符转换为小写    <?php echo strtolower("Hello WORLD."); ?>  
    字符串拼接 .
    = "$a = 'hello'; $b = 'world'; echo ""$a $b"";"
    htmlentities 字符-》HTML实体

    按照原来格式输出 echo
    "<pre>"; echo "</pre>";
    去字符两遍空格
    /字符截断 trim " string trim ( string $str [, string $charlist ] ) - 去除字符串首尾处的空白字符(或者其他字符)   trim()函数当第二个参数为空时,默认去掉空格、制表符、换行符、回车符、垂直制表符等,当加入第二个参数时     1) trim(' ""string""', '""sg');   // 最终输出:""strin     2) trim(' ""string"" ', '""sg'); // 最终输出:""string""     2)trim('""string""', '""sg');    // 最终输出:trin   所以trim()函数优先去掉字符首尾的空白字符,再过滤掉给定的要去除的字符(列表),也适用于ltrim()、rtrim()函数 字符替换 preg_replace "\或\\ 和\即可 七个斜杠过滤三个斜杆和四个斜杠

    外部命令执行函数

    system

    exec

    passthru

    shell_exec

    反撇号 (`) 操作符

  • 相关阅读:
    W phase 学习
    有限破裂矩张量的发展历史
    Capjoint
    JavaScript之Function类型
    ThreadLocal学习资料
    Shiro学习资料
    jstl学习资料
    分页框架pager-taglib学习笔记
    MyBatis3学习笔记(曹锋老师版)
    关于处理日期格式化问题遇到的一个坑
  • 原文地址:https://www.cnblogs.com/AtesetEnginner/p/11316604.html
Copyright © 2011-2022 走看看