douzuo0002 2017-11-24 12:19
浏览 51
已采纳

php用于阻止某些URL的变量

I am writing a function in php for blocking some urls like Scam & Fraud or profanity. It should be act like a filter or validation rule. I am just confusing which variable is best for this purpose.

1. trim()
2. strippos ()

or do you have any better solutions then this .?

Function would be like this

function validation($data) {
$data = trim(https://www.url.com, https://www.url1.com ...);
return data;
}

OR

 function validation($data) {
    $data = stripos(https://www.url.com, https://www.url1.com ...);
    return data;
    }
  • 写回答

1条回答 默认 最新

  • dsklfsdlkf1232 2017-11-24 12:28
    关注

    That ain't gonna work. I'd list all the url's you want to check in an array and search in there;

    function is_url_allowed($url) {
        $not_allowed = array(
            'google.com',
            'facebook.com',
            'usa.gov'
        );
        $parsed_url = parse_url($url, PHP_URL_HOST);
        return !in_array($parsed_url, $not_allowed);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?