disable file_get_contents

Discussion in 'PHP' started by jonhyhar, Apr 1, 2010.

  1. #1
    hi guys, someone steals data from my site, how can I disable "file_get_contents"? thanks :(
     
    jonhyhar, Apr 1, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    If its your own server, find php.ini (or create in root if doesnt exist) - and insert the following:

    disable_functions =file_get_contents
    Code (markup):
    If its a remote server/site which is scraping your content, you can try disabling/manipulating their HTTP_REFERER via php or htaccess, - and echo a message/or redirect if the HTTP_REFERER matches the site which is scraping your content, however this method is unreliable as cURL can easily manipulate the HTTP_REFERER...

    Take alook at the following:

    http://www.javascriptkit.com/howto/htaccess14.shtml
     
    danx10, Apr 2, 2010 IP
  3. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    thank you danx10 :)
     
    jonhyhar, Apr 2, 2010 IP
  4. kbluhm

    kbluhm Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you know the IP address of their site (find it by pinging the site or logging access attempts), you can block access using their web site's IP address using $_SERVER['REMOTE_ADDR'].

    But $_SERVER['REMOTE_ADDR'] is not always reliable. There are other locations that may exist with the client's true IP address:
    - $_SERVER['HTTP_CLIENT_IP']
    - $_SERVER['HTTP_X_FORWARDED_FOR']
    - $_SERVER['HTTP_PC_REMOTE_ADDR']

    
    function get_ip_address()
    {
    	static $ip_address;
    	if ( NULL === $ip_address )
    	{
    		// where are we looking?
    		$locations = array(
    			'HTTP_CLIENT_IP',
    			'REMOTE_ADDR',
    			'HTTP_X_FORWARDED_FOR',
    			'HTTP_PC_REMOTE_ADDR',
    		);
    		// search for the IP address
    		foreach ( $locations as $location )
    		{
    			if ( isset( $_SERVER[ $location ] ) )
    			{
    				$ip_address = $_SERVER[ $location ];
    				break;
    			}
    		}
    		// may contain multiple addresses
    		if ( FALSE !== strpos( $ip_address, ',' ) )
    		{
    			$ip_address = explode( ',', $ip_address );
    			$ip_address = end( $ip_address );
    		}
    		$ip_address = trim( $ip_address );
    		// match the ip address against an IPv4 pattern matcher
    		if ( ! preg_match( '/^\d{1,3}(\.\d{1,3}){3}$/', $ip_address ) )
    		{
    			$ip_address = '0.0.0.0';
    		}
    	}
    	return $ip_address;
    }
    
    PHP:
    Usage:
    
    $banned_sites = array(
    	'123.45.67.890',
    	'0.0.0.0',
    );
    
    if ( in_array( get_ip_address(), $banned_sites ) )
    {
    	exit( 'Inappropriate access detected' );
    }
    
    PHP:
     
    kbluhm, Apr 2, 2010 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    As soon as they detect that they're blocked they'll start using a proxy, assuming they're not routing requests through random proxies already.
    Just try and detect them, then slip a couple of in-content links back to yourself into the pages you return to the scrapers.

    Blocking scrapers always turns out to be a losing battle in the long run. If you can find ways to take advantage of them you'll do much better.
     
    joebert, Apr 2, 2010 IP
  6. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Have a look at the HTML obfuscator care of IonCube: located here. I have no idea how they do it but the page does render with no discernible source - see their example.
     
    Rory M, Apr 2, 2010 IP
  7. canadianguy_001

    canadianguy_001 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Attempting to obfuscate HTML is:

    a) futile
    b) a great way to get horrible placement in search engines
     
    canadianguy_001, Apr 2, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    Furthermore its js 'obfuscation', which means its unsafe.
     
    danx10, Apr 3, 2010 IP
  9. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #9
    Which is why you output non obfuscated HTML to search engine spiders :eek:
     
    Alex Roxon, Apr 3, 2010 IP
  10. Brandon.Add.On

    Brandon.Add.On Peon

    Messages:
    178
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Well as stated before trying to block scrapers is always a losing battle especially since you run the risk of blocking search engines. Instead you can either find advantages in the small window of opportunity ie placing links in the text, copyrights and keywords back to your site or even cut the article and place a Rest Of Article... link at the end of the piece.
     
    Brandon.Add.On, Apr 3, 2010 IP