Jump to content

Recommended Posts

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 )

Link to comment
https://forums.phpfreaks.com/topic/249910-blocking-certain-urls-in-a-php-form/
Share on other sites

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;

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;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.