random user agent

Discussion in 'PHP' started by BAM78, Feb 18, 2010.

  1. #1
    How can I make this script do a random user agent
    I want it to use about 4 different agents
    Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
    Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 360SE)



    <?php
    ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7');
    $data = file_get_contents('http://www.site.com/key.php');
    $regex = '/(.*?)</';
    preg_match($regex,$data,$match);
    
    $key = $match[1];
    
    
    
    ?>
    
    PHP:

     
    BAM78, Feb 18, 2010 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    <?php
    $agents[] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
    $agents[] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
    $agents[] = "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10";
    $agents[] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 360SE)";

    $random = rand(0,3);

    print $agents[$random];

    ini_set('user_agent', $agents[$random]);
    $data = file_get_contents('http://www.site.com/key.php');
    $regex = '/(.*?)</';
    preg_match($regex,$data,$match);

    $key = $match[1];


    ?>
     
    crivion, Feb 18, 2010 IP
  3. BAM78

    BAM78 Peon

    Messages:
    115
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks! works nice :)
     
    BAM78, Feb 18, 2010 IP