如何自动更新网页的URI? [英] How to update the URI of the webpage automatically?

查看:142
本文介绍了如何自动更新网页的URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

?>


推荐答案

尝试此解决方案:

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

这篇关于如何自动更新网页的URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆