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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度