Skip to content

Commit 16e6908

Browse files
authored
add new Model
This is the Info class which contains various methods to retrieve information about the user and the server.
1 parent 421ef35 commit 16e6908

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

App/Models/Info.php

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
3+
namespace Monster\App\Models;
4+
5+
/*
6+
This is the Info class which contains various methods to retrieve information about the user and the server.
7+
*/
8+
9+
class Info
10+
{
11+
12+
/*
13+
Retrieves the domain name of the server.
14+
@return string The domain name of the server.
15+
*/
16+
public function Domain()
17+
{
18+
return $_SERVER['SERVER_NAME'];
19+
}
20+
21+
/*
22+
Retrieves the host name used in the HTTP request.
23+
@return string The host name used in the HTTP request.
24+
*/
25+
public function Host()
26+
{
27+
return $_SERVER['HTTP_HOST'];
28+
}
29+
30+
/*
31+
Retrieves the IP address of the server's host.
32+
@return string The IP address of the server's host.
33+
*/
34+
public function HostIP()
35+
{
36+
return gethostbyname($_SERVER['SERVER_NAME']);
37+
}
38+
39+
/*
40+
Retrieves the IP address of the user making the request.
41+
@return string The IP address of the user making the request.
42+
*/
43+
public function UserIP()
44+
{
45+
return $_SERVER['REMOTE_ADDR'];
46+
}
47+
48+
/*
49+
Retrieves the cookies sent by the user.
50+
@return array An associative array of cookies sent by the user.
51+
*/
52+
public function Cookies()
53+
{
54+
return $_COOKIE;
55+
}
56+
57+
/*
58+
Retrieves the full cookie string sent by the user.
59+
@return string The full cookie string sent by the user.
60+
*/
61+
public function FullCookie()
62+
{
63+
return $_SERVER['HTTP_COOKIE'];
64+
}
65+
66+
/*
67+
Retrieves the path of the current request.
68+
@return string The path of the current request.
69+
*/
70+
public function Path()
71+
{
72+
return $_SERVER['REQUEST_URI'];
73+
}
74+
75+
/*
76+
Retrieves the type of device used by the user.
77+
@return string The type of device used by the user (Mobile, Tablet, or Desktop).
78+
*/
79+
public function Device()
80+
{
81+
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
82+
if (strpos($userAgent, 'mobile') !== false) {
83+
return 'Mobile';
84+
} elseif (strpos($userAgent, 'tablet') !== false) {
85+
return 'Tablet';
86+
} else {
87+
return 'Desktop';
88+
}
89+
}
90+
91+
/*
92+
Retrieves the user agent string sent by the user.
93+
@return string The user agent string sent by the user.
94+
*/
95+
public function UserAgent()
96+
{
97+
return $_SERVER['HTTP_USER_AGENT'];
98+
}
99+
100+
/*
101+
Retrieves the HTTP headers sent by the user.
102+
@return array An associative array of HTTP headers sent by the user.
103+
*/
104+
public function getHeaders()
105+
{
106+
$headers = [];
107+
foreach ($_SERVER as $name => $value) {
108+
if (strpos($name, 'HTTP') === 0) {
109+
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
110+
}
111+
}
112+
return $headers;
113+
}
114+
115+
/*
116+
Echoes the cookies sent by the user.
117+
*/
118+
public function echoCookies()
119+
{
120+
$cookies = $_COOKIE;
121+
foreach ($cookies as $key => $value) {
122+
echo $key . ': ' . $value . '<br>';
123+
}
124+
}
125+
126+
/*
127+
128+
Retrieves the operating system of the user.
129+
130+
@return string The operating system of the user.
131+
*/
132+
public function getOS()
133+
{
134+
$userAgent = $_SERVER['HTTP_USER_AGENT'];
135+
$devices = [
136+
'Windows Phone' => 'Windows Phone',
137+
'iPhone' => 'iPhone',
138+
'iPad' => 'iPad',
139+
'Kindle' => 'Silk',
140+
'Android' => 'Android',
141+
'PlayBook' => 'PlayBook',
142+
'BlackBerry' => 'BlackBerry',
143+
'Macintosh' => 'Macintosh',
144+
'Linux' => 'Linux',
145+
'Windows' => 'Windows'
146+
];
147+
148+
foreach ($devices as $os => $device) {
149+
if (strpos($userAgent, $device) !== false) {
150+
return $os;
151+
}
152+
}
153+
154+
return 'Unknown';
155+
}
156+
}

0 commit comments

Comments
 (0)