Skip to content

Instantly share code, notes, and snippets.

@guanlisheng
Last active March 14, 2020 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guanlisheng/85a2e5e586519b04b27e5ede74b34080 to your computer and use it in GitHub Desktop.
Save guanlisheng/85a2e5e586519b04b27e5ede74b34080 to your computer and use it in GitHub Desktop.
<?php
require_once "../Webservice/db_functions.php";
require_once "../Webservice/send_mail.php";
require_once "../Webservice/utility.php";
function getIpAddress()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($ips[count($ips) - 1]);
}
else
return $_SERVER['REMOTE_ADDR'];
}
if (
isset($_GET["User_ID"]) && isset($_GET["Version"])
&& isset($_GET["Platform"]) && isset($_GET["OperatingSystem"])
&& isset($_GET["Language"]) && isset($_GET["Country"]) && isset($_GET["Resolution"])
&& isset($_GET["Start_Time"]) && isset($_GET["End_Time"])
)
{
if (
!empty($_GET["User_ID"]) && !empty($_GET["Version"])
&& !empty($_GET["Platform"]) && !empty($_GET["OperatingSystem"])
&& !empty($_GET["Language"]) && /*!empty($_GET["Country"]) && */ !empty($_GET["Resolution"])
&& !empty($_GET["Start_Time"]) && !empty($_GET["End_Time"])
)
{
$User_ID = $_GET["User_ID"];
$Version = $_GET["Version"];
$Platform = $_GET["Platform"];
$OperatingSystem = $_GET["OperatingSystem"];
$Language = $_GET["Language"];
if ($_GET["Country"] != "")
$Country = $_GET["Country"];
else
$Country = Localize::getLocationInfoByIp(getIpAddress());
$Resolution = $_GET["Resolution"];
$Start_Time = date ($_GET["Start_Time"]);
$End_Time = date ($_GET["End_Time"]);
//DB_Insert::insert_main_stats($User_ID, $Version, $Platform, $OperatingSystem,
// $Language, $Country, $Resolution, $Start_Time, $End_Time);
$data = array (
'v' => 1,
't' => 'pageview',
'tid' => 'UA-51521761-6',
'cid' => $User_ID,
'uid' => $User_ID,
'dp' => '/dpplaceholder',
'dt' => 'dtplaceholder',
'ul' => $Language,
'sr' => $Resolution,
'an' => 'MoneyManagerEx',
'av' => $Version,
'uip' => getIpAddress(),
'cd1' => $Platform
);
$url = 'https://www.google-analytics.com/collect?';
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'user_agent' => $OperatingSystem,
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
}
else
{
echo ("Required parameter empty");
$Message = "Required parameter empty:"."<br>";
foreach ($_GET as $Key => $Value)
{
$Message .= $Key." = '${Value}'";
$Message .= "<br>";
}
$Message .= "<br>"."<br>"."Server data:"."<br>";
foreach ($_SERVER as $Key => $Value)
{
$Message .= $Key." = '${Value}'";
$Message .= "<br>";
}
Send_Mail::OnError($Message);
}
}
else
{
echo ("Required parameter missing");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment