Advertisement
ozh

Checking URL against down blacklist servers

ozh
Sep 12th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. require_once( dirname(__FILE__).'/includes/load-yourls.php' );
  3.  
  4. // Let's test a legit URL
  5. $url = 'https://www.google.com/';
  6.  
  7. // Below is code from the plugin, modified to var_dump() instead of return a result
  8.  
  9. $parsed = parse_url( $url );
  10.  
  11. if( !isset( $parsed['host'] ) )
  12.     return yourls_apply_filter( 'ozh_yourls_antispam_malformed', 'malformed' );
  13.  
  14. // Remove www. from domain (but not from www.com)
  15. $parsed['host'] = preg_replace( '/^www\.(.+\.)/i', '$1', $parsed['host'] );
  16.  
  17. // Major blacklists. There's a filter if you want to manipulate this.
  18. $blacklists = yourls_apply_filter( 'ozh_yourls_antispam_list',
  19.     array(
  20.         'zen.spamhaus.org',
  21.         'multi.surbl.org',
  22.         'black.uribl.com',
  23.         'nope.niet.nein',
  24.     )
  25. );
  26.  
  27. // Check against each blacklist, exit if blacklisted
  28. foreach( $blacklists as $blacklist ) {
  29.     $domain = $parsed['host'] . '.' . $blacklist . '.';
  30.     $record = @dns_get_record( $domain );
  31.    
  32.     var_dump( $blacklist, $record );
  33. }
  34.  
  35. /* RESULT :
  36.  **********
  37.  
  38. string 'zen.spamhaus.org' (length=16)
  39.  
  40. array (size=0)
  41.   empty
  42.  
  43. string 'multi.surbl.org' (length=15)
  44.  
  45. array (size=0)
  46.   empty
  47.  
  48. string 'black.uribl.com' (length=15)
  49.  
  50. array (size=0)
  51.   empty
  52.  
  53. string 'nope.niet.nein' (length=14)
  54.  
  55. array (size=0)
  56.   empty
  57.  
  58. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement