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);";
?>