I made a php-mysql counter for my webpage.
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.
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. So each time you use the function its like opening the page again.
It should avoid the count issue you are having.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.