浏览器信息获取 - 用户行为分析与数据采集
浏览器信息获取
| User Agent: | |
| 浏览器唯一指纹: | |
| 用户进入时间: | |
| Cookie: | |
| IP地址: | |
| 经纬度地址: | 
<script>
	// 获取浏览器信息
	document.getElementById('ua').innerText = navigator.userAgent;
	// 获取浏览器唯一指纹
	new Fingerprint2().get(function(result) {
		document.getElementById('fp').innerText = result;
	});
	// 获取用户进入时间
	document.getElementById('time').innerText = new Date().toLocaleString();
	// 获取Cookie
	document.getElementById('cookie').innerText = document.cookie;
	// 获取IP地址和经纬度地址
	const geo = new Promise((resolve, reject) => {
		if ('geolocation' in navigator) {
			navigator.geolocation.getCurrentPosition(
				position => {
					resolve(position.coords.latitude + ',' + position.coords.longitude);
				},
				error => {
					reject(error.message);
				}
			);
		} else {
			reject('Geolocation is not supported by this browser.');
		}
	});
	geo.then(result => {
		document.getElementById('location').innerText = result;
		// 发送数据到PHP
		const xhr = new XMLHttpRequest();
		xhr.open('POST', 'save.php', true);
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr.send('ua=' + encodeURIComponent(navigator.userAgent) +
		         '&fp=' + encodeURIComponent(result) +
		         '&time=' + encodeURIComponent(new Date().toLocaleString()) +
		         '&cookie=' + encodeURIComponent(document.cookie) +
		         '&ip=' + encodeURIComponent(result.split(',')[0]) +
		         '&location=' + encodeURIComponent(result));
	}).catch(error => {
		console.log(error);
	});
</script>
<?php
	// 保存数据到txt文件
	$data = $_POST['ua'] . '\t' . 
	        $_POST['fp'] . '\t' . 
	        $_POST['time'] . '\t' . 
	        $_POST['cookie'] . '\t' . 
	        $_POST['ip'] . '\t' . 
	        $_POST['location'] . '\n';
	file_put_contents('data.txt', $data, FILE_APPEND);
	// 输出保存成功信息
	echo '保存成功!';
?>
原文地址: https://www.cveoy.top/t/topic/mChf 著作权归作者所有。请勿转载和采集!