{source}
<?php
// Hash function using SHA256 algorithm
function hashValue($value) {
return hash('sha256', $value);
}
$url = 'https://geolocation-db.com/jsonp/';
// Make a cURL request to get the location information
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
// Extract the location data from the response
$location = json_decode(substr($response, 9, -1));
$country = $location->country_name;
$country_code = $location->country_code;
$city = $location->city;
$IPv4 = $location->IPv4;
$state = $location->state;
// Set the API endpoint URL
$url = 'https://graph.facebook.com/v16.0/659512358056331/events?access_token=EAAF40pPkvUgBAHe7U0dIHRF6f5k4IWqjQU2kUMb8anqQqzg1fdT3LJiZBKwNpZCOw7WeBsZCsUNahdGEiinJv8GnCXEmVB8tFuyo6uCI8PpB70lPkHZBZBDeOKixHSxNrxDK1EWN86cGJZAo7KNsjbJywKEgi4cZBU0istxJV2QxyRgepUewuoTxIJZCTQxjBioZD';
// Set the data to be sent in the request
$data = array(
'data' => array(
array(
'event_name' => 'PageView',
'event_time' => time(),
'action_source' => 'website',
'user_data' => array(
'country' => array(
// Use the lowercase, 2-letter country codes in ISO 3166-1 alpha-2
hashValue($country) ?? null,
),
'ct' => array(
// Using Roman alphabet a-z characters is recommended. Lowercase only with no punctuation, no special characters, and no spaces.
hashValue($city) ?? null,
),
'st' => array(
// Use the 2-character ANSI abbreviation code in lowercase.
hashValue($state) ?? null,
),
'client_ip_address' => $_SERVER['REMOTE_ADDR'] ?? null,
'client_user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? null,
'fbp'=>$_COOKIE['_fbp']??null,
'fbc'=>$_COOKIE['_fbc']??null
),
),
),
);
$ch = curl_init();
// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Execute the cURL request
$result = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
$error_message = 'cURL error: ' . curl_error($ch);
//echo "<script>console.log('$error_message');</script>";
} else {
// Handle the success
$response_message = 'Response: ' . $result;
//$why=$data['data'][0]['user_data']['fbp'];
//echo "<script>console.log('$why');</script>";
// echo "<script>console.log('$response_message');</script>";
}
// Close the cURL session
curl_close($ch);
?>
{/source}