PHP判断路径是否合法,不能有./ ../等安全隐患

5年以前  |  阅读数:909 次  |  编程语言:PHP 

./, ../,常被黑客用来逃脱即有路径,以进行越权访问。这个PHP方法用来判断路径中是否这些危险内容。

    function is_path_legal($path)
    {
        if($path == null){
            return true;
        }

        $pos = strpos($path,"..");
        if( $pos === 0 || $pos > 0 ){
            return false;
        }

        return true;
    }

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8