Код: Выделить всё
const fpPromise = import('https://fpjscdn.net/v3/sample')[b] .then(FingerprintJS => FingerprintJS.load());
// Analyze the visitor when necessary.
fpPromise
.then(fp => fp.get())
.then(result => {
console.log(result.requestId, result.visitorId);
var visitorId = result.visitorId;
console.log(visitorId);
// Call the function to send the value to PHP
send_value_php(visitorId);
})
.catch(error => console.error(error));
function send_value_php(visitorId) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(xmlhttp.responseText); // Correct console.log position
}
};
var url = "./test.php";
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Construct the parameter string
var params = "userID=" + encodeURIComponent(visitorId);
// Send the AJAX request with the parameters
xmlhttp.send(params);
}
Код: Выделить всё
public static function Authentication($user, $pass)
{
$username = User::login($user, $pass);
if ($username) {
$userid = new User($user);
$conn = Database::getConnection();
$ip = $_SERVER['REMOTE_ADDR'];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$token = md5(rand(0, 999999) . $ip . $user_agent . time());
// Check if the 'userID' is set in the POST data
// Check if the 'userID' parameter is set in the POST request
error_log(print_r($_POST, true));
if (isset($_POST['userID'])) {
// Retrieve the value of 'userID'
$userId = $_POST['userID'];
// Now you can use $userId variable in your PHP script
echo "Received userID: " . $userId;
// Here, you can perform any additional processing with the received userID,
// such as storing it in a database or using it for further operations.
} else {
// If 'userID' parameter is not set in the POST request
echo "No userID received";
}
}
}
Я пытаюсь отправить идентификатор посетителя в php для аутентификации. Объект XMLHttpRequest[/b] и ajax предупредили об успехе сообщения. но php не получил значения, я также использую инструмент браузера для отладки. но инструмент не выявил никаких проблем, работает нормально. но php не получил значение $_POST в php.
Код: Выделить всё
[Thu Mar 14 04:57:08.573425 2024] [php:warn] [pid 1500] [client 172.30.1.154:52409] PHP Warning: Undefined variable $fingerPrint_userId
Источник: https://stackoverflow.com/questions/781 ... -js-to-php
Мобильная версия