Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Update UserAgent.php #511

Merged
merged 2 commits into from
May 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/Faker/Provider/UserAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public static function chrome()
$saf = mt_rand(531, 536) . mt_rand(0, 2);

$platforms = array(
'(' . static::linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(13, 15) . '.0.' . mt_rand(800, 899) . ".0 Safari/$saf",
'(' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(13, 15) . '.0.' . mt_rand(800, 899) . ".0 Safari/$saf",
'(' . static::macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(13, 15) . '.0.' . mt_rand(800, 899) . ".0 Safari/$saf"
'(' . static::linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(36, 40) . '.0.' . mt_rand(800, 899) . ".0 Mobile Safari/$saf",
'(' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(36, 40) . '.0.' . mt_rand(800, 899) . ".0 Mobile Safari/$saf",
'(' . static::macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . mt_rand(36, 40) . '.0.' . mt_rand(800, 899) . ".0 Mobile Safari/$saf"
);

return 'Mozilla/5.0 ' . static::randomElement($platforms);
Expand All @@ -80,16 +80,12 @@ public static function chrome()
*/
public static function firefox()
{
$ver = array(
'Gecko/' . date('Ymd', mt_rand(strtotime('2011-1-1'), time())) . ' Firefox/' . mt_rand(4, 15) . '.0',
'Gecko/' . date('Ymd', mt_rand(strtotime('2010-1-1'), time())) . ' Firefox/3.6.' . mt_rand(1, 20),
'Gecko/' . date('Ymd', mt_rand(strtotime('2010-1-1'), time())) . ' Firefox/3.8'
);
$ver = 'Gecko/' . date('Ymd', mt_rand(strtotime('2010-1-1'), time())) . ' Firefox/' . mt_rand(35, 37) . '.0';

$platforms = array(
'(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . '; rv:1.9.' . mt_rand(0, 2) . '.20) ' . static::randomElement($ver),
'(' . static::linuxPlatformToken() . '; rv:' . mt_rand(5, 7) . '.0) ' . static::randomElement($ver),
'(' . static::macPlatformToken() . ' rv:' . mt_rand(2, 6) . '.0) ' . static::randomElement($ver)
'(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . '; rv:1.9.' . mt_rand(0, 2) . '.20) ' . $ver,
'(' . static::linuxPlatformToken() . '; rv:' . mt_rand(5, 7) . '.0) ' . $ver,
'(' . static::macPlatformToken() . ' rv:' . mt_rand(2, 6) . '.0) ' . $ver
);

return "Mozilla/5.0 " . static::randomElement($platforms);
Expand All @@ -108,15 +104,21 @@ public static function safari()
} else {
$ver = mt_rand(4, 5) . '.0.' . mt_rand(1, 5);
}

$mobileDevices = array(
'iPhone; CPU iPhone OS',
'iPad; CPU OS'
);

$platforms = array(
'(Windows; U; ' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
'(' . static::macPlatformToken() . ' rv:' . mt_rand(2, 6) . '.0; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
'(iPod; U; CPU iPhone OS ' . mt_rand(3, 4) . '_' . mt_rand(0, 3) . ' like Mac OS X; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/" . mt_rand(3, 4) . ".0.5 Mobile/8B" . mt_rand(111, 119) . " Safari/6$saf",
'(' . static::randomElement($mobileDevices) . ' ' . mt_rand(7, 8) . '_' . mt_rand(0, 2) . '_' . mt_rand(1, 2) . ' like Mac OS X; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/" . mt_rand(3, 4) . ".0.5 Mobile/8B" . mt_rand(111, 119) . " Safari/6$saf",
);

return "Mozilla/5.0 " . static::randomElement($platforms);
}


/**
* Generate Opera user agent
Expand All @@ -126,8 +128,8 @@ public static function safari()
public static function opera()
{
$platforms = array(
'(' . static::linuxPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.9.' . mt_rand(160, 190) . ' Version/' . mt_rand(10, 12) . '.00',
'(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.9.' . mt_rand(160, 190) . ' Version/' . mt_rand(10, 12) . '.00'
'(' . static::linuxPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.' . mt_rand(8, 12) . '.' . mt_rand(160, 355) . ' Version/' . mt_rand(10, 12) . '.00',
'(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.' . mt_rand(8, 12) . '.' . mt_rand(160, 355) . ' Version/' . mt_rand(10, 12) . '.00'
);

return "Opera/" . mt_rand(8, 9) . '.' . mt_rand(10, 99) . ' ' . static::randomElement($platforms);
Expand All @@ -140,8 +142,7 @@ public static function opera()
*/
public static function internetExplorer()
{
return 'Mozilla/5.0 (compatible; MSIE ' . mt_rand(5, 9) . '.0; ' . static::windowsPlatformToken() . '; Trident/' . mt_rand(3, 5) . '.' . mt_rand(0, 1) . ')';

return 'Mozilla/5.0 (compatible; MSIE ' . mt_rand(5, 11) . '.0; ' . static::windowsPlatformToken() . '; Trident/' . mt_rand(3, 5) . '.' . mt_rand(0, 1) . ')';
}

public static function windowsPlatformToken()
Expand Down