Prevent curl connection to adtwirl server for pc users.

Started on the old forum in August 2010 · view the original in the archive · old links redirect here

7 replies · 624 views · started 16 years ago · 3 min read

3 participants
GumSlone Administrator Principal · 1,690 posts #1

Since there are no pc ads in the adtwirl network and every pc user who clicks adtwirl ad will see this message.

ad id:633 You can access this ad only with a mobile phone. Mobile advertising powered by adtwirl.com.

you can block the curl request to adtwirl network, if you modify the code a bit with the following function which you can download from: Detect Mobile Browsers - Mobile User Agent Detection

this will reduce the usage your server ressouces and your server load.

you need to add this piece of code on the top of the adtwirl_request function:

$mobile = mobile_device_detect();
if($mobile == false) return ''; 

combined it will look like:

function adtwirl_request($ads_number = 1, $use_array = true)
    {
      $mobile = mobile_device_detect();
if($mobile == false) return '';

    // PHP Install Code Version: 21.05.2010 v 1.05.00 BETA
      // Unique id code of your site
      $site_code = '0e621fab-693d-4457-982b-b884c0ddc6f4';
      // Enable image ads (true = enable ; false = disable )
      $image_ads = true;
      // Enable adult ads (true = enable ; false = disable )
      $adult_ads = true;
      /* Enable free ads (true = enable ; false = disable ) you will get points instead of Money for this ads which you can use to advertise your site, if this ads are disabled your site will show only cash ads */
      $free_ads = true;
      
      $request_method = 1; /* You can chose here the request method for ads, but the best value is 1 which stands for curl request method. Any other value will be readfile which is not recomended. */
      
      // Do not edit from this line
      $IP = ""; if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $IP = $_SERVER["HTTP_X_FORWARDED_FOR"]; $proxy = $_SERVER["REMOTE_ADDR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $IP = $_SERVER["HTTP_CLIENT_IP"]; } elseif (isset($_SERVER["HTTP_X_REAL_IP"])) { $IP = $_SERVER["HTTP_X_REAL_IP"]; } else { $IP = $_SERVER["REMOTE_ADDR"]; } } else { if (getenv('HTTP_X_FORWARDED_FOR')) { $IP = getenv('HTTP_X_FORWARDED_FOR'); $proxy = getenv('REMOTE_ADDR'); } elseif (getenv('HTTP_CLIENT_IP')) { $IP = getenv('HTTP_CLIENT_IP'); } else { $IP = getenv('REMOTE_ADDR'); } } if (strstr($IP, ',')) { $ips = explode(',', $IP); $IP = $ips[0]; } if (empty($IP)) $IP = $_SERVER["REMOTE_ADDR"]; elseif (strtolower(trim($IP)) == 'unknown') $IP = $_SERVER["REMOTE_ADDR"]; $keyname_ua_arr = array('HTTP_X_DEVICE_USER_AGENT', 'HTTP_X_OPERAMINI_PHONE_UA', 'HTTP_USER_AGENT'); foreach ($keyname_ua_arr as $keyname_ua) { if (!empty($_SERVER[$keyname_ua])) { $ua = urlencode($_SERVER[$keyname_ua]); break; } } $url = 'http://a.adtwirl.com/ad.php?site_code='.$site_code.'&ip='.urlencode($IP).'&ua='.$ua.'&uri='.urlencode($_SERVER["REQUEST_URI"]).'&host='.urlencode($_SERVER["HTTP_HOST"]).'&lang='.urlencode($_SERVER["HTTP_ACCEPT_LANGUAGE"]).'&adult='.$adult_ads.'&free='.$free_ads.'&image='.$image_ads.'&ads='.$ads_number.'&code=28-3-10'; if($request_method == 1) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); } else { ini_set('default_socket_timeout',1); if (@$file = fopen($url, "r")) { while(!feof($file)) { $result .= fgets($file, 1024); } fclose ($file); } }
      if ($use_array == true && $ads_number > 1)
        {
          $arr = explode("\n", $result);
          $ads = array();
          for($i=0;$i<$ads_number;$i++)
          {
              if(preg_match('/^\<.*\>$/', $arr[$i])) $ads[] = $arr[$i];
          }
          if(count($ads)>0)return $ads;
        }
      elseif(preg_match('/^\<.*\>$/', $result)) 
          return $result;
    }

Done

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

khan Lead · 681 posts #5

Adtwirl gives me problem On my html Pages. Basically my pages are valid html 4.1, but when I add your adds then a user of mine says pages are not valid. Then I try to validate those page. I saw your ads give me Warning. not the actual error. but it gives me warning.:)

GumSlone Administrator Principal · 1,690 posts #6

khan89 wrote: Adtwirl gives me problem On my html Pages. Basically my pages are valid html 4.1, but when I add your adds then a user of mine says pages are not valid. Then I try to validate those page. I saw your ads give me Warning. not the actual error. but it gives me warning.:)

which warning?

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

khan Lead · 681 posts #7

GumSlone wrote: which warning?

  1. Warning Line 68, Column 696: NET-enabling start-tag requires SHORTTAG YES
  …c="http://a.adtwirl.com/ad.gif" alt=""/></a> ['). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.
  1. Warning Line 68, Column 2796: NET-enabling start-tag requires SHORTTAG YES

    …c="http://a.adtwirl.com/ad.gif" alt=""/>](http://c.adtwirl.com/cli…

%20%20%20%20%20%20✉

%20%20%20%20%20%20The%20sequence%20<FOO%20/>%20can%20be%20interpreted%20in%20at%20least%20two%20different%20ways,%20depending%20on%20the%20DOCTYPE%20of%20the%20document.%20For%20HTML%204.01%20Strict,%20the) <a href="http://c.adtwirl.com/cli…

  ✉

  The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.
GumSlone Administrator Principal · 1,690 posts #8

Malka1 wrote: This is stupid question, of course i did!

works fine for me.

<?php
error_reporting(1);
require_once('mobile_device_detect.php');

function adtwirl_request($ads_number = 1, $use_array = true) 
    { 
      $mobile = mobile_device_detect(); 
		if($mobile == false) return ''; 

    // PHP Install Code Version: 21.05.2010 v 1.05.00 BETA 
      // Unique id code of your site 
      $site_code = '0e621fab-693d-4457-982b-b884c0ddc6f4'; 
      // Enable image ads (true = enable ; false = disable ) 
      $image_ads = true; 
      // Enable adult ads (true = enable ; false = disable ) 
      $adult_ads = true; 
      /* Enable free ads (true = enable ; false = disable ) you will get points instead of Money for this ads which you can use to advertise your site, if this ads are disabled your site will show only cash ads */ 
      $free_ads = true; 
       
      $request_method = 1; /* You can chose here the request method for ads, but the best value is 1 which stands for curl request method. Any other value will be readfile which is not recomended. */ 
       
      // Do not edit from this line 
      $IP = ""; if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $IP = $_SERVER["HTTP_X_FORWARDED_FOR"]; $proxy = $_SERVER["REMOTE_ADDR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $IP = $_SERVER["HTTP_CLIENT_IP"]; } elseif (isset($_SERVER["HTTP_X_REAL_IP"])) { $IP = $_SERVER["HTTP_X_REAL_IP"]; } else { $IP = $_SERVER["REMOTE_ADDR"]; } } else { if (getenv('HTTP_X_FORWARDED_FOR')) { $IP = getenv('HTTP_X_FORWARDED_FOR'); $proxy = getenv('REMOTE_ADDR'); } elseif (getenv('HTTP_CLIENT_IP')) { $IP = getenv('HTTP_CLIENT_IP'); } else { $IP = getenv('REMOTE_ADDR'); } } if (strstr($IP, ',')) { $ips = explode(',', $IP); $IP = $ips[0]; } if (empty($IP)) $IP = $_SERVER["REMOTE_ADDR"]; elseif (strtolower(trim($IP)) == 'unknown') $IP = $_SERVER["REMOTE_ADDR"]; $keyname_ua_arr = array('HTTP_X_DEVICE_USER_AGENT', 'HTTP_X_OPERAMINI_PHONE_UA', 'HTTP_USER_AGENT'); foreach ($keyname_ua_arr as $keyname_ua) { if (!empty($_SERVER[$keyname_ua])) { $ua = urlencode($_SERVER[$keyname_ua]); break; } } $url = 'http://a.adtwirl.com/ad.php?site_code='.$site_code.'&ip='.urlencode($IP).'&ua='.$ua.'&uri='.urlencode($_SERVER["REQUEST_URI"]).'&host='.urlencode($_SERVER["HTTP_HOST"]).'&lang='.urlencode($_SERVER["HTTP_ACCEPT_LANGUAGE"]).'&adult='.$adult_ads.'&free='.$free_ads.'&image='.$image_ads.'&ads='.$ads_number.'&code=28-3-10'; if($request_method == 1) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); } else { ini_set('default_socket_timeout',1); if (@$file = fopen($url, "r")) { while(!feof($file)) { $result .= fgets($file, 1024); } fclose ($file); } } 
      if ($use_array == true && $ads_number > 1) 
        { 
          $arr = explode("\n", $result); 
          $ads = array(); 
          for($i=0;$i<$ads_number;$i++) 
          { 
              if(preg_match('/^\<.*\>$/', $arr[$i])) $ads[] = $arr[$i]; 
          } 
          if(count($ads)>0)return $ads; 
        } 
      elseif(preg_match('/^\<.*\>$/', $result))  
          return $result; 
    } 
echo adtwirl_request();
echo 'test';

?>

Added after 28 minutes:

khan89 wrote:

  1. Warning Line 68, Column 696: NET-enabling start-tag requires SHORTTAG YES

    …c="http://a.adtwirl.com/ad.gif" alt=""/></a> ['). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.

  2. Warning Line 68, Column 2796: NET-enabling start-tag requires SHORTTAG YES

    …c="http://a.adtwirl.com/ad.gif" alt=""/>](http://c.adtwirl.com/cli…

%20%20%20%20%20%20✉

%20%20%20%20%20%20The%20sequence%20<FOO%20/>%20can%20be%20interpreted%20in%20at%20least%20two%20different%20ways,%20depending%20on%20the%20DOCTYPE%20of%20the%20document.%20For%20HTML%204.01%20Strict,%20the) <a onclick="pageTracker.trackPageview ('/outgoing/http_c_adtwirl_com_cli_8230_9993_The_sequence_FOO');" rel="nofollow" href="http://c.adtwirl.com/cli…

  ✉

  The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.

dont know what its all about, but with w3c validator and standard mobile doctype everything should be ok.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close