How to update the URI of the webpage automatically?

▼魔方 西西 提交于 2020-01-14 05:47:08

问题


I have a table called files where there are columns such as id, name, webpage, visitors. There are list of files already in the table. Now I have created new columns called webpage and visitors. The webpage is the URI of the file and the visitors is the counter views of the file. The problem is that I wanted to update the webpage and visitors automatically using session but I can't. Can you please help me.

<?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:


Try this solution:

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


来源:https://stackoverflow.com/questions/22504989/how-to-update-the-uri-of-the-webpage-automatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!