Advertisement
RaBiitch

randomua.class

Oct 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.25 KB | None | 0 0
  1. <?php
  2.    
  3. /**
  4.  * Random user agent creator
  5.  * @since Sep 28, 2012
  6.  * @version 1.0
  7.  * @link http://burgosoft.com/php-scripts/random-uagent/
  8.  * @author Randolph Burgos (exeQutor)
  9.  * @filesource https://github.com/lukapusic/random-uagent
  10.  */
  11.  
  12.  class Random_UA
  13.  {
  14.    
  15.     /**
  16.      *
  17.      */
  18.     var $linux_proc;
  19.     /**
  20.      *
  21.      */
  22.     var $mac_proc;
  23.    
  24.     /**
  25.      * A
  26.      */
  27.     var $lang;
  28.    
  29.     function __construct()
  30.     {
  31.         $this->linux_proc = array(
  32.             'i686',
  33.             'x86_64'
  34.         );
  35.        
  36.         $this->mac_proc = array(
  37.             'Intel',
  38.             'PPC',
  39.             'U; Intel',
  40.             'U; PPC'
  41.         );
  42.        
  43.         $this->lang = array(
  44.             'en-US',
  45.             'sl-SI'
  46.         );
  47.     }
  48.    
  49.     function firefox() {
  50.         $ver = array(
  51.         'Gecko/' . date('Ymd', rand(strtotime('2011-1-1'), mktime())) . ' Firefox/' . rand(5, 7) . '.0',
  52.         'Gecko/' . date('Ymd', rand(strtotime('2011-1-1'), mktime())) . ' Firefox/' . rand(5, 7) . '.0.1',
  53.         'Gecko/' . date('Ymd', rand(strtotime('2010-1-1'), mktime())) . ' Firefox/3.6.' . rand(1, 20),
  54.         'Gecko/' . date('Ymd', rand(strtotime('2010-1-1'), mktime())) . ' Firefox/3.8'
  55.         );
  56.    
  57.         $platforms = array(
  58.         '(Windows NT ' . rand(5, 6) . '.' . rand(0, 1) . '; ' . $this->lang[array_rand($this->lang, 1)] . '; rv:1.9.' . rand(0, 2) . '.20) ' . $ver[array_rand($ver, 1)],
  59.         '(X11; Linux ' . $this->linux_proc[array_rand($this->linux_proc, 1)] . '; rv:' . rand(5, 7) . '.0) ' . $ver[array_rand($ver, 1)],
  60.         '(Macintosh; ' . $this->mac_proc[array_rand($this->mac_proc, 1)] . ' Mac OS X 10_' . rand(5, 7) . '_' . rand(0, 9) . ' rv:' . rand(2, 6) . '.0) ' . $ver[array_rand($ver, 1)]
  61.         );
  62.    
  63.         return $platforms[array_rand($platforms, 1)];
  64.     }
  65.    
  66.     function safari() {
  67.         $saf = rand(531, 535) . '.' . rand(1, 50) . '.' . rand(1, 7);
  68.         if (rand(0, 1) == 0) {
  69.         $ver = rand(4, 5) . '.' . rand(0, 1);
  70.         } else {
  71.         $ver = rand(4, 5) . '.0.' . rand(1, 5);
  72.         }
  73.    
  74.         $platforms = array(
  75.         '(Windows; U; Windows NT ' . rand(5, 6) . '.' . rand(0, 1) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
  76.         '(Macintosh; U; ' . $this->mac_proc[array_rand($this->mac_proc, 1)] . ' Mac OS X 10_' . rand(5, 7) . '_' . rand(0, 9) . ' rv:' . rand(2, 6) . '.0; ' . $this->lang[array_rand($this->lang, 1)] . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
  77.         '(iPod; U; CPU iPhone OS ' . rand(3, 4) . '_' . rand(0, 3) . ' like Mac OS X; ' . $this->lang[array_rand($this->lang, 1)] . ") AppleWebKit/$saf (KHTML, like Gecko) Version/" . rand(3, 4) . ".0.5 Mobile/8B" . rand(111, 119) . " Safari/6$saf",
  78.         );
  79.    
  80.         return $platforms[array_rand($platforms, 1)];
  81.     }
  82.    
  83.     function iexplorer() {
  84.         $ie_extra = array(
  85.         '',
  86.         '; .NET CLR 1.1.' . rand(4320, 4325) . '',
  87.         '; WOW64'
  88.         );
  89.         $platforms = array(
  90.         '(compatible; MSIE ' . rand(5, 9) . '.0; Windows NT ' . rand(5, 6) . '.' . rand(0, 1) . '; Trident/' . rand(3, 5) . '.' . rand(0, 1) . ')'
  91.         );
  92.    
  93.         return $platforms[array_rand($platforms, 1)];
  94.     }
  95.    
  96.     function opera() {
  97.         $op_extra = array(
  98.         '',
  99.         '; .NET CLR 1.1.' . rand(4320, 4325) . '',
  100.         '; WOW64'
  101.         );
  102.         $platforms = array(
  103.         '(X11; Linux ' . $this->linux_proc[array_rand($this->linux_proc, 1)] . '; U; ' . $this->lang[array_rand($this->lang, 1)] . ') Presto/2.9.' . rand(160, 190) . ' Version/' . rand(10, 12) . '.00',
  104.         '(Windows NT ' . rand(5, 6) . '.' . rand(0, 1) . '; U; ' . $this->lang[array_rand($this->lang, 1)] . ') Presto/2.9.' . rand(160, 190) . ' Version/' . rand(10, 12) . '.00'
  105.         );
  106.    
  107.         return $platforms[array_rand($platforms, 1)];
  108.     }
  109.    
  110.     function chrome() {
  111.         $saf = rand(531, 536) . rand(0, 2);
  112.    
  113.         $platforms = array(
  114.         '(X11; Linux ' . $this->linux_proc[array_rand($this->linux_proc, 1)] . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . rand(13, 15) . '.0.' . rand(800, 899) . ".0 Safari/$saf",
  115.         '(Windows NT ' . rand(5, 6) . '.' . rand(0, 1) . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . rand(13, 15) . '.0.' . rand(800, 899) . ".0 Safari/$saf",
  116.         '(Macintosh; U; ' . $this->mac_proc[array_rand($this->mac_proc, 1)] . ' Mac OS X 10_' . rand(5, 7) . '_' . rand(0, 9) . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . rand(13, 15) . '.0.' . rand(800, 899) . ".0 Safari/$saf"
  117.         );
  118.    
  119.         return $platforms[array_rand($platforms, 1)];
  120.     }
  121.    
  122.     /**
  123.      * Main function which will choose random browser
  124.      * @return string user agent
  125.      */
  126.     function generate() {
  127.         $x = rand(1, 5);
  128.         switch ($x) {
  129.         case 1:
  130.             return "Mozilla/5.0 " . $this->firefox();
  131.             break;
  132.         case 2:
  133.             return "Mozilla/5.0 " . $this->safari();
  134.             break;
  135.         case 3:
  136.             return "Mozilla/" . rand(4, 5) . ".0 " . $this->iexplorer();
  137.             break;
  138.         case 4:
  139.             return "Opera/" . rand(8, 9) . '.' . rand(10, 99) . ' ' . $this->opera();
  140.             break;
  141.         case 5:
  142.             return 'Mozilla/5.0' . $this->chrome();
  143.             break;
  144.         }
  145.     }
  146.    
  147. }
  148.  
  149. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement