= $_SERVER['HTTP_USER_AGENT'];
als ik $_SERVER['HTTP_USER_AGENT']; doe op mijn telefoon zie ik dit.
Mozilla/5.0 (Linux; U; Android 4.3; nl-nl; GT-I9300 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
en dan gaat het niet om alleen mijn telefoon.
nu zou ik graag de versie Android er uit vissen en het type telefoon.
ik zou graag een detectie maken voor me website als er word gekeken met een telefoon dat ik een andere site kan laten opstarten zo dat het duidelijker leesbaar wordt.
wie kan me een stuk op weg helpen
http://code.google.com/p/php-mobile-detect/wiki/Mobile_Detect
Verder zou je ook kunnen kijken naar 'responsive design',waarbij je layout de juiste vorm aan neemt met de gebruikte resolutie.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// $u_agent = $_SERVER['HTTP_USER_AGENT'];
$u_agent = 'Mozilla/5.0 (Linux; U; Android 4.3; nl-nl; GT-I9300 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
// $u_agent = 'Mozilla/5.0 (Linux; Android 4.2.2; C6603 Build/10.3.1.A.2.67) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.99 Mobile Safari/537.36';
// $u_agent = 'Mozilla/5.0 (Linux; U; Android 4.1.1; nl-nl; AT-AS40SE Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
$useragent = $u_agent;
$uagent = $u_agent;
$bname = 'Unknown';
$platform = 'Unknown';
$mobile = 'nee';
$version= "";
$ub = 'Unknown';
//Mobile
if (preg_match('/Mobile/', $u_agent)) {
$mobile = 'ja';
}
// Build
if (preg_match('/Build/', $u_agent)) {
echo strlen('Build')." X";
}
if (preg_match('/Blackberry/i', $u_agent)) {
$bname = 'Blackberry';
$platform = 'Unknown';
$version= "";
$ub = 'Unknown';
}
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
if (preg_match('/Android/i', $u_agent)) {
$platform = 'Android';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/Windows NT 5.1|win32/i', $u_agent)) {
$platform = 'Windows XP';
}
elseif (preg_match('/Windows NT 6.0|win32/i', $u_agent)) {
$platform = 'Windows Vista';
}
elseif (preg_match('/Windows NT 6.1|win32/i', $u_agent)) {
$platform = 'Windows 7';
}
elseif (preg_match('/Windows NT 6.2|win32/i', $u_agent)) {
$platform = 'Windows 8';
}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$bname = 'Mozilla Firefox';
$ub = "Firefox";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$bname = 'Google Chrome';
$ub = "Chrome";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$bname = 'Opera';
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$bname = 'Netscape';
$ub = "Netscape";
}
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i == 0) {
} else {
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
$version= $matches['version'][0];
}
else {
$version= $matches['version'][1];
}
}
else {
$version= $matches['version'][0];
}
}
// check if we have a number
if ($version==null || $version=="") {$version="?";}
if (preg_match('/Trident/i', $u_agent)) {
if (preg_match('/4.0/i', $u_agent)) {
$version = '8';
}
elseif(preg_match('/5.0/i',$u_agent))
{
$version = '9';
}
}
return array(
'userAgent' => $u_agent,
'name' => $bname,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern,
'mobile' => $mobile
);
}
$u_agent = 'Mozilla/5.0 (Linux; U; Android 4.3; nl-nl; GT-I9300 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
// $u_agent = 'Mozilla/5.0 (Linux; Android 4.2.2; C6603 Build/10.3.1.A.2.67) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.99 Mobile Safari/537.36';
// $u_agent = 'Mozilla/5.0 (Linux; U; Android 4.1.1; nl-nl; AT-AS40SE Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
$useragent = $u_agent;
$uagent = $u_agent;
$bname = 'Unknown';
$platform = 'Unknown';
$mobile = 'nee';
$version= "";
$ub = 'Unknown';
//Mobile
if (preg_match('/Mobile/', $u_agent)) {
$mobile = 'ja';
}
// Build
if (preg_match('/Build/', $u_agent)) {
echo strlen('Build')." X";
}
if (preg_match('/Blackberry/i', $u_agent)) {
$bname = 'Blackberry';
$platform = 'Unknown';
$version= "";
$ub = 'Unknown';
}
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
if (preg_match('/Android/i', $u_agent)) {
$platform = 'Android';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/Windows NT 5.1|win32/i', $u_agent)) {
$platform = 'Windows XP';
}
elseif (preg_match('/Windows NT 6.0|win32/i', $u_agent)) {
$platform = 'Windows Vista';
}
elseif (preg_match('/Windows NT 6.1|win32/i', $u_agent)) {
$platform = 'Windows 7';
}
elseif (preg_match('/Windows NT 6.2|win32/i', $u_agent)) {
$platform = 'Windows 8';
}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$bname = 'Mozilla Firefox';
$ub = "Firefox";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$bname = 'Google Chrome';
$ub = "Chrome";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$bname = 'Opera';
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$bname = 'Netscape';
$ub = "Netscape";
}
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i == 0) {
} else {
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
$version= $matches['version'][0];
}
else {
$version= $matches['version'][1];
}
}
else {
$version= $matches['version'][0];
}
}
// check if we have a number
if ($version==null || $version=="") {$version="?";}
if (preg_match('/Trident/i', $u_agent)) {
if (preg_match('/4.0/i', $u_agent)) {
$version = '8';
}
elseif(preg_match('/5.0/i',$u_agent))
{
$version = '9';
}
}
return array(
'userAgent' => $u_agent,
'name' => $bname,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern,
'mobile' => $mobile
);
}
wat ik er nu nog uit wil hebben is
Android 4.2.2;
C6603 Build
zoeken naar android gaat wel maar nu de getallen er achter tot de punt komma,
en het type telefoon en dat is eigenlijk van af punt koma tot aan Build.
ik heb een aantal test strings van verschillende telefoons gevonden
Toevoeging op 26/01/2014 13:43:35:
het vinden aan de rechter kant is me gelukt
met
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
$adroidaan = (explode(';', $u_agent));
$aantal = count($adroidaan);
for ($i = 0; $i <= $aantal-1; $i++) {
if (preg_match('/Android/i', $adroidaan[$i])) {
$platform = $adroidaan[$i];
}
}
$aantal = count($adroidaan);
for ($i = 0; $i <= $aantal-1; $i++) {
if (preg_match('/Android/i', $adroidaan[$i])) {
$platform = $adroidaan[$i];
}
}
maar hoe kom ik links van Build?