php »ç¿ëÀÚ Á¢¼ÓIP, ºê¶ó¿ìÀúÁ¤º¸, osÁ¤º¸, http, https Á¢¼ÓÇÁ·ÎÅäÄÝ ¾Ë¾Æ¿À±â |
|
|
|
4³â Àü |
À¥»çÀÌÆ®¿¡ Á¢¼ÓÇÑ »ç¿ëÀÚÀÇ Á¤º¸¸¦ Àоî¿À´Â ºÎºÐÀ» ±â·ÏÇÕ´Ï´Ù
¾Æ·¡¿Í °°ÀÌ HTTP_USER_AGENT ¸¦ Àоî¿À¸é
$userAgent = $_SERVER["HTTP_USER_AGENT"];
´ÙÀ½°ú °°Àº ¹®ÀÚ¿ÀÌ ¹ÝȯµË´Ï´Ù
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
À§ Á¤º¸¸¦ Parsing Çؼ ºê¶ó¿ìÀú Á¤º¸¿Í OS Á¤º¸¸¸ µû·Î »Ì¾Æ³»·Á¸é ´ÙÀ½°ú °°Àº ÇÔ¼ö¸¦ »ç¿ëÇÏ½Ã¸é µË´Ï´Ù
function getBrowserInfo()
{
$userAgent = $_SERVER["HTTP_USER_AGENT"];
if(preg_match('/MSIE/i',$userAgent) && !preg_match('/Opera/i',$u_agent)){
$browser = 'Internet Explorer';
}
else if(preg_match('/Firefox/i',$userAgent)){
$browser = 'Mozilla Firefox';
}
else if (preg_match('/Chrome/i',$userAgent)){
$browser = 'Google Chrome';
}
else if(preg_match('/Safari/i',$userAgent)){
$browser = 'Apple Safari';
}
elseif(preg_match('/Opera/i',$userAgent)){
$browser = 'Opera';
}
elseif(preg_match('/Netscape/i',$userAgent)){
$browser = 'Netscape';
}
else{
$browser = "Other";
}
return $browser;
}
echo getBrowserInfo();
OSÁ¤º¸¸¦ Àоî¿À·Á¸é ´ÙÀ½°ú °°ÀÌ ÇÏ½Ã¸é µË´Ï´Ù
function getOsInfo()
{
$userAgent = $_SERVER["HTTP_USER_AGENT"];
if (preg_match('/linux/i', $userAgent)){
$os = 'linux';}
elseif(preg_match('/macintosh|mac os x/i', $userAgent)){
$os = 'mac';}
elseif (preg_match('/windows|win32/i', $userAgent)){
$os = 'windows';}
else {
$os = 'Other';
}
return $os;
}
echo getOsInfo();
¾Æ¿ï·¯, »ç¿ëÀÚ°¡ http ·Î Á¢¼ÓÇß´ÂÁö ¾Æ´Ï¸é https ÇÁ·ÎÅäÄÝ·Î Á¢¼ÓÇß´ÂÁö ¾Ë¾Æ³»·Á¸é
´ÙÀ½°ú °°Àº ¹æ¹ýÀÌ ÀÖ½À´Ï´Ù
function IsHttps() {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443;
}
echo IsHttps();
https ·Î Á¢¼ÓÇßÀ» °æ¿ì 1 ÀÌ ¹ÝȯµË´Ï´Ù
Àú´Â ƯÁ¤ÆäÀÌÁöÀÇ Á¢¼Ó±â·ÏÀ» È®ÀÎÇÏ°í ½ÍÀ» °æ¿ì¿¡, ´ÙÀ½°ú °°ÀÌ ¸¸µé¾î³õ°í, ÇÊ¿äÇÑ ÆäÀÌÁö¿¡ include ÇÏ¿© »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù.
//############################################################
//# START : Á¢¼Ó±â·ÏÀ» ³²±ä´Ù
//############################################################
function getBrowserInfo()
{
$userAgent = $_SERVER["HTTP_USER_AGENT"];
if(preg_match('/MSIE/i',$userAgent) && !preg_match('/Opera/i',$u_agent)){
$browser = 'Internet Explorer';
}
else if(preg_match('/Firefox/i',$userAgent)){
$browser = 'Mozilla Firefox';
}
else if (preg_match('/Chrome/i',$userAgent)){
$browser = 'Google Chrome';
}
else if(preg_match('/Safari/i',$userAgent)){
$browser = 'Apple Safari';
}
elseif(preg_match('/Opera/i',$userAgent)){
$browser = 'Opera';
}
elseif(preg_match('/Netscape/i',$userAgent)){
$browser = 'Netscape';
}
else{
$browser = "Other";
}
return $browser;
}
function getOsInfo()
{
$userAgent = $_SERVER["HTTP_USER_AGENT"];
if (preg_match('/linux/i', $userAgent)){
$os = 'linux';}
elseif(preg_match('/macintosh|mac os x/i', $userAgent)){
$os = 'mac';}
elseif (preg_match('/windows|win32/i', $userAgent)){
$os = 'windows';}
else {
$os = 'Other';}
return $os;
}
// https Á¢¼ÓÀÏ °æ¿ì 1À» ¹ÝȯÇÑ´Ù
function isSecure() {
return
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| $_SERVER['SERVER_PORT'] == 443;
}
$user_agent = $_SERVER["HTTP_USER_AGENT"];
$browser = getBrowserInfo();
$os = getOsInfo();
$arrDay= array('ÀÏ¿äÀÏ','¿ù¿äÀÏ','È¿äÀÏ','¼ö¿äÀÏ','¸ñ¿äÀÏ','±Ý¿äÀÏ','Åä¿äÀÏ');
$date = date('w'); //0 ~ 6 ¼ýÀÚ ¹Ýȯ
$static_page_url = $_SERVER["PHP_SELF"];
$static_dayofweek = $arrDay[$date];
$static_access_time = date("H");
$static_user_ip = getenv('REMOTE_ADDR');
$static_enroll_date = date("Y") . date("m") . date("d");
$static_signdate = time();
$static_year = date("Y");
$static_month = date("m");
$static_day = date("d");
// https Á¢¼ÓÀÏ °æ¿ì¸¸ ±â·ÏÇÑ´Ù. http Á¢¼ÓÀº webalizer ¿¡ ±â·ÏµÈ´Ù
if (isSecure())
{
$STATISTICS_QUERY = "INSERT INTO statistics ( user_agent, browser, os, year, month, day, page_url, dayofweek, access_time, user_ip, enroll_date, signdate ) VALUES ( '$user_agent', '$browser', '$os', '$static_year', '$static_month', '$static_day', '$static_page_url', '$static_dayofweek', '$static_access_time', '$static_user_ip', '$static_enroll_date', '$static_signdate' ) ";
$result = mysqli_query($dbconn,$STATISTICS_QUERY);
}
//############################################################
//# END : Á¢¼Ó±â·ÏÀ» ³²±ä´Ù
//############################################################
À§¿Í °°ÀÌ Çϸé, »ç¿ëÀÚÀÇ IP, ºê¶ó¿ìÀú, os, Á¢¼ÓÀÏÀÚ, ÆäÀÌÁöURL, ¿äÀÏ, ½Ã°£ µîÀÇ Á¤º¸¸¦ DB¿¡ ÀúÀåÇÒ ¼ö ÀÖ½À´Ï´Ù
|
|
̵̧ : 234 |
̵̧
¸ñ·Ï
|
|