-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHPLesson10obj2Final.php
More file actions
109 lines (81 loc) · 3.84 KB
/
PHPLesson10obj2Final.php
File metadata and controls
109 lines (81 loc) · 3.84 KB
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
<?php
//this code identifies IP addresses that begin with "202" and denies them access to the download options
$deny = array("202.*.*.*");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header("location: http://dianaprince.usersource.com/denialofservice.html");
exit();
} else {
// these functions will discover the user's operating system and browser combo
//and translate them into more intelligible language using associative arrays
$user_agent = $_SERVER['HTTP_USER_AGENT'];
function getOS() {
global $user_agent;
$os_platform = "Unknown OS Platform";
$os_array = array(
'/windows nt 6.2/i' => 'Windows',
'/windows nt 6.1/i' => 'Windows',
'/windows nt 6.0/i' => 'Windows',
'/windows nt 5.2/i' => 'Windows',
'/windows nt 5.1/i' => 'Windows',
'/windows xp/i' => 'Windows',
'/windows nt 5.0/i' => 'Windows',
'/windows me/i' => 'Windows',
'/win98/i' => 'Windows',
'/win95/i' => 'Windows',
'/win16/i' => 'Windows',
'/macintosh|mac os x/i' => 'Mac OS',
'/mac_powerpc/i' => 'Mac OS',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
foreach ($os_array as $regex => $value) {
if (preg_match($regex, $user_agent)) {
$os_platform = $value;
}
}
return $os_platform;
}
function getBrowser() {
global $user_agent;
$browser = "Unknown Browser";
$browser_array = array(
'/msie/i' => 'Internet Explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/opera/i' => 'Opera',
'/netscape/i' => 'Netscape',
'/maxthon/i' => 'Maxthon',
'/konqueror/i' => 'Konqueror',
'/mobile/i' => 'Handheld Browser'
);
foreach ($browser_array as $regex => $value) {
if (preg_match($regex, $user_agent)) {
$browser = $value;
}
}
return $browser;
}
$user_os = getOS();
$user_browser = getBrowser();
}
//this code checks to make sure the user's operating system and browser are compatible with the software
//and sends the user to the appropriate page to download the software if the systems are compatible
if ($user_os == 'Mac OS' && $user_browser == 'Firefox') {
header("location: http://dianaprince.usersource.com/downloadMac.html");
} else if ($user_os == 'Mac OS' && $user_browser != 'Firefox') {
header("location: http://dianaprince.usersource.com/downloadFirefox.html");
} else if ($user_os == 'Windows' && $user_browser == 'Firefox') {
header("location: http://dianaprince.usersource.com/downloadWin-FF.html");
} else if ($user_os == 'Windows' && $user_browser == 'Internet Explorer') {
header("location: http://dianaprince.usersource.com/downloadWin-IE.html");
} else {
echo "We're sorry, but your operating system and/or browser are not compatible with our software.<br/><br/>";
}
?>