Only your own ads script

Discussion in 'PHP' started by wierdo, Oct 22, 2007.

  1. #1
    I need that PHP script that was posted (or another one) for selecting certain IPs to show ads to. I want to block mine as well as my school's IPs because some "friends" are threatening to click bomb me.
     
    wierdo, Oct 22, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <?php
    # These should be the ips you wanna show different ads too ...
    $block_ips = array(
    	'84.556.78.90',
    	'83.334.54.67',
    	'86.162.24.120'
    );
    # This is the normal advert code that you will display to most people ...
    $normal_ads = <<<NORMALADS
    The normal adcode here, with no special syntax
    NORMALADS;
    # This is dummy adcode that you display to the ppl in block_ips ...
    $blocked_ads = <<<BLOCKADS
    The blocked ads here, with no special syntax
    BLOCKADS;
    # This should be called in your code where you want to display the adverts ...
    function show_appropriate_ads(  )
    {
    	global $block_ips, $normal_ads, $blocked_ads ;
    	
    	if( $_SERVER['X_FORWARDED_FOR'] )
    	{
    		if( strpos( $_SERVER['X_FORWARDED_FOR'], ',' ) !== false )
    		{
    			foreach( split( ',', $_SERVER['X_FORWARDED_FOR'] ) as $ip )
    			{
    				if( in_array( trim( $ip ), $block_ips ) )
    				{
    					return $blocked_ads ;	
    				}
    			}
    		}	
    	}
    	elseif( $_SERVER['REMOTE_ADDR'] )
    	{
    		if( in_array( $_SERVER['REMOTE_ADDR'], $block_ips ) )
    		{
    			return $blocked_ads ;
    		}
    	}
    	return $normal_ads ;
    }
    ?>
    <!-- some dummy html to test this shit out -->
    <html>
    <body>
    	Welcome to the page ...
    	<div id="ads"><?=show_appropriate_ads( ) ?></div>
    </body>
    </html>
    
    PHP:
    aaahhhhh.....
     
    krakjoe, Oct 22, 2007 IP
  3. wierdo

    wierdo Well-Known Member

    Messages:
    1,646
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    140
    #3
    I'm trying to display this on a header php page that is used on the pages across my site, but it appears not to be blocking my IP.
     
    wierdo, Oct 22, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    paste your whole code ....
     
    krakjoe, Oct 23, 2007 IP