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:
<?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]; ?>