testing7 Posted October 27, 2011 Share Posted October 27, 2011 im sure i am missing something simple. but this is killing me. i get this to work: $url = (isset($_POST['url'])) ? $_POST['url'] : ''; $BlockedNames = array('nepwk', 'teleworm'); $BlockedDomains = array('nepwk.com', 'teleworm.com', 'yopmail.com', 'adf.ly', 'www.nepwk.com'); @list($name, $domain) = explode("http://", $url); else if(in_array($name, $BlockedNames) || in_array($domain, $BlockedDomains)) { $mesaj = "<div class=\"msg\"<div class=\"error\">Your URL has been blocked by our system!</div></div>"; } now the above works if i type the whole domain for every single url i want to block but i want to know is how would i add a catch all of sorts to the domain so say the domain is: http://www.google.com i want to block everything google so all of the following would be blocked as well http://www.google.com/whatever http://www.google.com/anything http://www.google.com/something i want all of those to be blocked automatically without having to add each individual one im trying to block adf.ly links which change for each person and each url they mask and i want to take proactive measure to just block them from being added into my form instead of having them added to my database then having to go and manually delete them. any questions or if this doesn't make sense let me know. thanks in advance (and maybe this is bad code im a noob so go easy ) Quote Link to comment https://forums.phpfreaks.com/topic/249910-blocking-certain-urls-in-a-php-form/ Share on other sites More sharing options...
The Little Guy Posted October 27, 2011 Share Posted October 27, 2011 Try this: $url = $_POST['url']; $url_info = (object)parse_url($url); $domain = str_replace("www.","",$url_info->host); $BlockedDomains = array('nepwk.com', 'teleworm.com', 'yopmail.com', 'adf.ly', 'nepwk.com'); $mesaj = "<div class=\"msg\">Your URL has been submitted!</div>"; if(in_array($domain, $BlockedDomains)){ $mesaj = "<div class=\"error\">Your URL has been blocked by our system!</div>"; } echo $mesaj; Quote Link to comment https://forums.phpfreaks.com/topic/249910-blocking-certain-urls-in-a-php-form/#findComment-1282683 Share on other sites More sharing options...
testing7 Posted October 27, 2011 Author Share Posted October 27, 2011 thank you jesus solved Quote Link to comment https://forums.phpfreaks.com/topic/249910-blocking-certain-urls-in-a-php-form/#findComment-1282688 Share on other sites More sharing options...
QuickOldCar Posted October 27, 2011 Share Posted October 27, 2011 That won't work if it's a subdomain, you would need to preg_match the urls, or parse the main domain from the url. Quote Link to comment https://forums.phpfreaks.com/topic/249910-blocking-certain-urls-in-a-php-form/#findComment-1282697 Share on other sites More sharing options...
The Little Guy Posted October 27, 2011 Share Posted October 27, 2011 Okay, this should handle sub-domains. <?php $url = $_POST['url']; if(!preg_match("/^(http:\/\/|https:\/\/)/", $url)){ $url = "http://$url"; } $url_info = (object)parse_url($url); $domain = preg_replace("/^www\./","",$url_info->host); $BlockedDomains = array('nepwk.com', 'teleworm.com', 'yopmail.com', 'adf.ly'); $mesaj = "<div class=\"msg\">Your URL has been submitted!</div>"; foreach($BlockedDomains as $dom){ $dom = preg_quote($dom); if(preg_match("/$dom/", $domain)){ $mesaj = "<div class=\"error\">Your URL has been blocked by our system!</div>"; break; } } echo $mesaj; ?> Quote Link to comment https://forums.phpfreaks.com/topic/249910-blocking-certain-urls-in-a-php-form/#findComment-1282707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.