ar_EG
1 year ago
ar_JO
1 year ago
ar_SA
1 year ago
at_AT
1 year ago
bg_BG
1 year ago
bn_BD
1 year ago
cs_CZ
1 year ago
da_DK
1 year ago
de_AT
1 year ago
de_CH
1 year ago
de_DE
1 year ago
el_CY
1 year ago
el_GR
1 year ago
en_AU
1 year ago
en_CA
1 year ago
en_GB
1 year ago
en_HK
1 year ago
en_IN
1 year ago
en_NG
1 year ago
en_NZ
1 year ago
en_PH
1 year ago
en_SG
1 year ago
en_UG
1 year ago
en_US
1 year ago
en_ZA
1 year ago
es_AR
1 year ago
es_ES
1 year ago
es_PE
1 year ago
es_VE
1 year ago
et_EE
1 year ago
fa_IR
1 year ago
fi_FI
1 year ago
fr_BE
1 year ago
fr_CA
1 year ago
fr_CH
1 year ago
fr_FR
1 year ago
he_IL
1 year ago
hr_HR
1 year ago
hu_HU
1 year ago
hy_AM
1 year ago
id_ID
1 year ago
is_IS
1 year ago
it_CH
1 year ago
it_IT
1 year ago
ja_JP
1 year ago
ka_GE
1 year ago
kk_KZ
1 year ago
ko_KR
1 year ago
lt_LT
1 year ago
lv_LV
1 year ago
me_ME
1 year ago
mn_MN
1 year ago
ms_MY
1 year ago
nb_NO
1 year ago
ne_NP
1 year ago
nl_BE
1 year ago
nl_NL
1 year ago
pl_PL
1 year ago
pt_BR
1 year ago
pt_PT
1 year ago
ro_MD
1 year ago
ro_RO
1 year ago
ru_RU
1 year ago
sk_SK
1 year ago
sl_SI
1 year ago
sr_Cyrl_RS
1 year ago
sr_Latn_RS
1 year ago
sr_RS
1 year ago
sv_SE
1 year ago
th_TH
1 year ago
tr_TR
1 year ago
uk_UA
1 year ago
vi_VN
1 year ago
zh_CN
1 year ago
zh_TW
1 year ago
Address.php
1 year ago
Barcode.php
1 year ago
Base.php
1 year ago
Biased.php
1 year ago
Color.php
1 year ago
Company.php
1 year ago
DateTime.php
1 year ago
File.php
1 year ago
HtmlLorem.php
1 year ago
Image.php
1 year ago
Internet.php
1 year ago
Lorem.php
1 year ago
Medical.php
1 year ago
Miscellaneous.php
1 year ago
Payment.php
1 year ago
Person.php
1 year ago
PhoneNumber.php
1 year ago
Text.php
1 year ago
UserAgent.php
1 year ago
Uuid.php
1 year ago
UserAgent.php
226 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @license MIT |
| 4 | * |
| 5 | * Modified by impress-org on 07-August-2024 using Strauss. |
| 6 | * @see https://github.com/BrianHenryIE/strauss |
| 7 | */ |
| 8 | |
| 9 | namespace Give\Vendors\Faker\Provider; |
| 10 | |
| 11 | class UserAgent extends Base |
| 12 | { |
| 13 | protected static $userAgents = ['firefox', 'chrome', 'internetExplorer', 'opera', 'safari', 'msedge']; |
| 14 | |
| 15 | protected static $windowsPlatformTokens = [ |
| 16 | 'Windows NT 6.2', 'Windows NT 6.1', 'Windows NT 6.0', 'Windows NT 5.2', 'Windows NT 5.1', |
| 17 | 'Windows NT 5.01', 'Windows NT 5.0', 'Windows NT 4.0', 'Windows 98; Win 9x 4.90', 'Windows 98', |
| 18 | 'Windows 95', 'Windows CE', |
| 19 | ]; |
| 20 | |
| 21 | /** |
| 22 | * Possible processors on Linux |
| 23 | */ |
| 24 | protected static $linuxProcessor = ['i686', 'x86_64']; |
| 25 | |
| 26 | /** |
| 27 | * Mac processors (it also added U;) |
| 28 | */ |
| 29 | protected static $macProcessor = ['Intel', 'PPC', 'U; Intel', 'U; PPC']; |
| 30 | |
| 31 | /** |
| 32 | * Add as many languages as you like. |
| 33 | */ |
| 34 | protected static $lang = ['en-US', 'sl-SI', 'nl-NL']; |
| 35 | |
| 36 | /** |
| 37 | * Generate mac processor |
| 38 | * |
| 39 | * @return string |
| 40 | */ |
| 41 | public static function macProcessor() |
| 42 | { |
| 43 | return static::randomElement(static::$macProcessor); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Generate linux processor |
| 48 | * |
| 49 | * @return string |
| 50 | */ |
| 51 | public static function linuxProcessor() |
| 52 | { |
| 53 | return static::randomElement(static::$linuxProcessor); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Generate a random user agent |
| 58 | * |
| 59 | * @example 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350' |
| 60 | * |
| 61 | * @return string |
| 62 | */ |
| 63 | public static function userAgent() |
| 64 | { |
| 65 | $userAgentName = static::randomElement(static::$userAgents); |
| 66 | |
| 67 | return static::$userAgentName(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Generate Chrome user agent |
| 72 | * |
| 73 | * @example 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312' |
| 74 | * |
| 75 | * @return string |
| 76 | */ |
| 77 | public static function chrome() |
| 78 | { |
| 79 | $saf = self::numberBetween(531, 536) . self::numberBetween(0, 2); |
| 80 | |
| 81 | $platforms = [ |
| 82 | '(' . static::linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . self::numberBetween(36, 40) . '.0.' . self::numberBetween(800, 899) . ".0 Mobile Safari/$saf", |
| 83 | '(' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . self::numberBetween(36, 40) . '.0.' . self::numberBetween(800, 899) . ".0 Mobile Safari/$saf", |
| 84 | '(' . static::macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . self::numberBetween(36, 40) . '.0.' . self::numberBetween(800, 899) . ".0 Mobile Safari/$saf", |
| 85 | ]; |
| 86 | |
| 87 | return 'Mozilla/5.0 ' . static::randomElement($platforms); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Generate Edge user agent |
| 92 | * |
| 93 | * @example 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36 Edg/99.0.1150.36' |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | public static function msedge() |
| 98 | { |
| 99 | $saf = self::numberBetween(531, 537) . '.' . self::numberBetween(0, 2); |
| 100 | $chrv = self::numberBetween(79, 99) . '.0'; |
| 101 | |
| 102 | $platforms = [ |
| 103 | '(' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . self::numberBetween(4000, 4844) . '.' . self::numberBetween(10, 99) . " Safari/$saf Edg/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99), |
| 104 | '(' . static::macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . self::numberBetween(4000, 4844) . '.' . self::numberBetween(10, 99) . " Safari/$saf Edg/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99), |
| 105 | '(' . static::linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . self::numberBetween(4000, 4844) . '.' . self::numberBetween(10, 99) . " Safari/$saf EdgA/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99), |
| 106 | '(' . static::iosMobileToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/15.0 EdgiOS/$chrv" . self::numberBetween(1000, 1146) . '.' . self::numberBetween(0, 99) . " Mobile/15E148 Safari/$saf", |
| 107 | ]; |
| 108 | |
| 109 | return 'Mozilla/5.0 ' . static::randomElement($platforms); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Generate Firefox user agent |
| 114 | * |
| 115 | * @example 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6' |
| 116 | * |
| 117 | * @return string |
| 118 | */ |
| 119 | public static function firefox() |
| 120 | { |
| 121 | $ver = 'Gecko/' . date('Ymd', self::numberBetween(strtotime('2010-1-1'), time())) . ' Firefox/' . self::numberBetween(35, 37) . '.0'; |
| 122 | |
| 123 | $platforms = [ |
| 124 | '(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . '; rv:1.9.' . self::numberBetween(0, 2) . '.20) ' . $ver, |
| 125 | '(' . static::linuxPlatformToken() . '; rv:' . self::numberBetween(5, 7) . '.0) ' . $ver, |
| 126 | '(' . static::macPlatformToken() . ' rv:' . self::numberBetween(2, 6) . '.0) ' . $ver, |
| 127 | ]; |
| 128 | |
| 129 | return 'Mozilla/5.0 ' . static::randomElement($platforms); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Generate Safari user agent |
| 134 | * |
| 135 | * @example 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_1 rv:3.0; en-US) AppleWebKit/534.11.3 (KHTML, like Gecko) Version/4.0 Safari/534.11.3' |
| 136 | * |
| 137 | * @return string |
| 138 | */ |
| 139 | public static function safari() |
| 140 | { |
| 141 | $saf = self::numberBetween(531, 535) . '.' . self::numberBetween(1, 50) . '.' . self::numberBetween(1, 7); |
| 142 | |
| 143 | if (Miscellaneous::boolean()) { |
| 144 | $ver = self::numberBetween(4, 5) . '.' . self::numberBetween(0, 1); |
| 145 | } else { |
| 146 | $ver = self::numberBetween(4, 5) . '.0.' . self::numberBetween(1, 5); |
| 147 | } |
| 148 | |
| 149 | $mobileDevices = [ |
| 150 | 'iPhone; CPU iPhone OS', |
| 151 | 'iPad; CPU OS', |
| 152 | ]; |
| 153 | |
| 154 | $platforms = [ |
| 155 | '(Windows; U; ' . static::windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf", |
| 156 | '(' . static::macPlatformToken() . ' rv:' . self::numberBetween(2, 6) . '.0; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf", |
| 157 | '(' . static::randomElement($mobileDevices) . ' ' . self::numberBetween(7, 8) . '_' . self::numberBetween(0, 2) . '_' . self::numberBetween(1, 2) . ' like Mac OS X; ' . static::randomElement(static::$lang) . ") AppleWebKit/$saf (KHTML, like Gecko) Version/" . self::numberBetween(3, 4) . '.0.5 Mobile/8B' . self::numberBetween(111, 119) . " Safari/6$saf", |
| 158 | ]; |
| 159 | |
| 160 | return 'Mozilla/5.0 ' . static::randomElement($platforms); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Generate Opera user agent |
| 165 | * |
| 166 | * @example 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00' |
| 167 | * |
| 168 | * @return string |
| 169 | */ |
| 170 | public static function opera() |
| 171 | { |
| 172 | $platforms = [ |
| 173 | '(' . static::linuxPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.' . self::numberBetween(8, 12) . '.' . self::numberBetween(160, 355) . ' Version/' . self::numberBetween(10, 12) . '.00', |
| 174 | '(' . static::windowsPlatformToken() . '; ' . static::randomElement(static::$lang) . ') Presto/2.' . self::numberBetween(8, 12) . '.' . self::numberBetween(160, 355) . ' Version/' . self::numberBetween(10, 12) . '.00', |
| 175 | ]; |
| 176 | |
| 177 | return 'Opera/' . self::numberBetween(8, 9) . '.' . self::numberBetween(10, 99) . ' ' . static::randomElement($platforms); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Generate Internet Explorer user agent |
| 182 | * |
| 183 | * @example 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)' |
| 184 | * |
| 185 | * @return string |
| 186 | */ |
| 187 | public static function internetExplorer() |
| 188 | { |
| 189 | return 'Mozilla/5.0 (compatible; MSIE ' . self::numberBetween(5, 11) . '.0; ' . static::windowsPlatformToken() . '; Trident/' . self::numberBetween(3, 5) . '.' . self::numberBetween(0, 1) . ')'; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * @return string |
| 194 | */ |
| 195 | public static function windowsPlatformToken() |
| 196 | { |
| 197 | return static::randomElement(static::$windowsPlatformTokens); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * @return string |
| 202 | */ |
| 203 | public static function macPlatformToken() |
| 204 | { |
| 205 | return 'Macintosh; ' . static::randomElement(static::$macProcessor) . ' Mac OS X 10_' . self::numberBetween(5, 8) . '_' . self::numberBetween(0, 9); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @return string |
| 210 | */ |
| 211 | public static function iosMobileToken() |
| 212 | { |
| 213 | $iosVer = self::numberBetween(13, 15) . '_' . self::numberBetween(0, 2); |
| 214 | |
| 215 | return 'iPhone; CPU iPhone OS ' . $iosVer . ' like Mac OS X'; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * @return string |
| 220 | */ |
| 221 | public static function linuxPlatformToken() |
| 222 | { |
| 223 | return 'X11; Linux ' . static::randomElement(static::$linuxProcessor); |
| 224 | } |
| 225 | } |
| 226 |