使用PHP获得屏幕分辨率我需要找到屏幕分辨率的用户谁访问我的网站屏幕?
3 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
jQuery:
$(function() {
$.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
if(json.outcome == 'success') {
// do something with the knowledge possibly?
} else {
alert('Unable to let PHP know what the screen resolution is!');
}
},'json');});PHP(Somescript.php)
<?php// For instance, you can do something like this:if(isset($_POST['width']) && isset($_POST['height'])) {
$_SESSION['screen_width'] = $_POST['width'];
$_SESSION['screen_height'] = $_POST['height'];
echo json_encode(array('outcome'=>'success'));} else {
echo json_encode(array('outcome'=>'error','error'=>"Couldn't save dimension info"));}?>
精慕HU
TA贡献1845条经验 获得超8个赞
<?php
session_start();if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height'])){
echo 'User resolution: ' . $_SESSION['screen_width'] . 'x' . $_SESSION['screen_height'];} else if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])) {
$_SESSION['screen_width'] = $_REQUEST['width'];
$_SESSION['screen_height'] = $_REQUEST['height'];
header('Location: ' . $_SERVER['PHP_SELF']);} else {
echo '<script type="text/javascript">window.location = "' . $_SERVER['PHP_SELF'] . '?width="+screen.width+"&height="+screen.height;</script>';}?>- 3 回答
- 0 关注
- 999 浏览
添加回答
举报
0/150
提交
取消
