简体   繁体   English

PHP-MySql中的计数器错误

[英]Counter error in PHP-MySql

I made a php-mysql counter for my webpage. 我为我的网页制作了一个php-mysql计数器。

When I add an image from another site to my site, the counter is not working correctly. 当我将其他网站的图像添加到我的网站时,计数器无法正常工作。

For checking the file exist or not on another site I use this code 为了检查文件是否存在于另一个站点,我使用此代码

<?php
function load_image($external_path,$internal_path)
{   
    if(@fopen($external_path,"r")==true)
    {
        return $external_path;
    }
    else
    {
        return $internal_path;
    }
}
?>

If it not found, then it shows from my site. 如果找不到,那么它会显示在我的网站上。

But it create a problem in counter. 但它在反击中造成了问题。

If I have 4 external image it increase as +4. 如果我有4个外部图像,它会增加为+4。

The increment code is as follows--- 增量代码如下---

<?php
class visitor
{
    function increment()
    {       
        $sql="select count_no from tbl_count"; 
        $result=DBAccess::execute_my_query($sql);
        if ($result!="") 
        {
            $rows=mysql_fetch_assoc($result);
            $visit_no=$rows['count_no'];    
        }   
        else
        {
            $first_visit_no=1;
            $sql1="insert into tbl_count (count_no) values ($first_visit_no)";
            $ins=DBAccess::execute_my_query($sql1);
        }
        $update_visit_no= $visit_no+1;
        $sql2="update tbl_count set count_no=$update_visit_no";
        $ins2=DBAccess::execute_my_query($sql2);                
        return $update_visit_no;
    }
}
?>

When you are using fopen the browser is doing a http request to the server. 当您使用fopen时,浏览器正在向服务器发出http请求。 So each time you use the function its like opening the page again. 因此,每次使用该功能时,就像再次打开页面一样。

Try file_get_contents() 尝试file_get_contents()

It should avoid the count issue you are having. 它应该避免你遇到的计数问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM