如何自动更新网页的URI?

时间:2014-03-19 11:53:09

标签: php html count uri

我有一个名为files的表,其中有id,name,webpage,visitor等列。表中已有文件列表。现在我创建了名为网页和访问者的新列。网页是文件的URI,访问者是文件的计数器视图。问题是我想使用会话自动更新网页和访问者,但我不能。你能帮我么。

<?php

session_start();

include_once"config.php";

$webpage=htmlspecialchars($_SERVER["REQUEST_URI"]);


$result=mysql_query("SELECT * FROM files WHERE webpage='$webpage'");
$num_rows = mysql_num_rows($result);
if ($num_rows == 0){
mysql_query("How to update the URI ($webpage) automatically? in the files table inside the column webpage");

}else{

if (!isset($_SESSION['webpage'])){$_SESSION['webpage'] = 0;
mysql_query("UPDATE files SET visitors=visitors+1 WHERE webpage='$webpage'");}}

?>

1 个答案:

答案 0 :(得分:0)

试试这个解决方案:

<?php

session_start();

include_once"config.php";

$webpage=htmlspecialchars($_SERVER["REQUEST_URI"]);


$result=mysql_query("SELECT * FROM files WHERE webpage='$webpage'");
$num_rows = mysql_num_rows($result);
if ($num_rows == 0)
{
    $_SESSION['webpage'][] = $webpage;
    mysql_query("INSERT INTO files (`id`,`name`,`webpage`,`visitors`) VALUES (null,'$name','$webpage','1')");
}
else
{
    if(is_array($_SESSION['webpage'])) && !in_array($webpage, $_SESSION['webpage'])))
    {
        $_SESSION['webpage'][] = $webpage;
        mysql_query("UPDATE files SET visitors=visitors+1 WHERE webpage='$webpage'");
    }
}
?>