日期:2012-07-14  浏览次数:20652 次

  本教程属于原创,转载请注明网页教学网

  今天给大家做出了一个能显示浏览者的屏幕分辨率的PHP代码,希望大家使用 一下,有什么问题请到论坛发帖讨论。

  首先新建一个文件取名为:resolution.php代码的内容如下:(注意:文件的扩展名必须是.PHP不要是.HTML)

<script language="javascript">
<!--
function writeCookie()
{
var today = new Date();
var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "users_res="+ screen.width +"x"+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie

location = '';
}

function checkRes(width, height) {
if(width != screen.width || height != screen.height) {
writeCookie();
} else {
return true;
}
}
//-->
</script>


<script language="javascript">
<!--
checkRes(1024, 768);
//-->
</script>



//网页教学网http://www.webjx.com 网页设计师的摇篮!!

  其次把下面的代码放到你想在哪显示访客的显示器分辨率信息的地方就可以了!( 下面代码当然也是放在扩展名为.PHP的文件中)

<?php 
$callget_res_page_name = $REQUEST_URI;
$GLOBALS[callget_res_page_name ] = $callget_res_page_name;
include("resolution.php");
echo $screen_width."x".$screen_height." is your screen resolution.";
?>

  注意:$应该是半角。