background image

PHP 源码: 实现静态 HTML 页面浏览次数统计代码

news.html
<!DOCTYPE   html   PUBLIC   “-//W3C//DTD   XHTML   1.0   Transitional//EN” 
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8  />

<title>记录访问次数</title>
<script type=”text/javascript”>
function getProfile(str) {
    var arr = str;
 alert(str);
    document.getElementById(‘nick’).innerHTML = arr;
}
</script>
</head>
<body>
<div id=”nick”></div>
<script type=”text/javascript” src=”act.php”></script>
</body>
</html>
 
act.php
<?php
$db = mysql_connect(‘localhost’,'root’, ’123456 ) or die (“

连接数据库失败 );

mysql_select_db(‘zend’, $db);
mysql_query(“SET NAMES  ‘utf8 ”);

mysql_query(“update info set msg=msg 1 where id=1 );

$sql = “select msg from info where id=1 ;

$rs  = mysql_query($sql);
$row = mysql_fetch_array($rs);
$str = $row['msg'];
$json_string = $str;
echo “getProfile($json_string);”;
?>