Mobile app version of vmapp.org
Login or Join
Barnes591

: Use Apache to prevent a PHP script from connecting to a specific domain Is there a way to prevent apache from connecting to a specific domain e.g. somesite.com? I have a PHP script that trying

@Barnes591

Posted in: #Apache #Php

Is there a way to prevent apache from connecting to a specific domain e.g. somesite.com?
I have a PHP script that trying to connect to specific host, and I would like to prevent that.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

3 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

I know this is somewhat hackish but it is dead simple to implement. If the script is attempting to connect to a dns based url (not an ip address based url), you could simply set your host file to point to 127.0.0.1 for that dns name only. This assumes you have no intention on browsing that particular site.

# in /etc/hosts
127.0.0.1 somedomainIwanttoAvoid.com


As a bonus, you can setup a virtual host locally to catch these requests and handle them however you want.

Good-luck!

10% popularity Vote Up Vote Down


 

@Angela700

If the PHP script is accepting parameters in the URL such as www.example.com/thescript.php?somesite.com you may be able to create a re-write in your .htaccess so anytime that URL is loaded it could simply refresh example.com

Or use an iptables rule such as iptables -A OUTPUT -d 0.0.0.0 -j DROP where the 0's are put the IP of the domain you want to block.

Having the php script modified would only be a few bucks on most freelance sites since it's pretty basic to add an if conditional statement that says if the URL entered is somesite.com don't execute.

10% popularity Vote Up Vote Down


 

@Barnes591

Here is an example of how to do this with htaccess. Note that it is relatively easy to circumvent the referer. The same website also has an example on blocking by IP.

Correction: I found this tutorial on IPTables. Perhaps that can get you started.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme