Jump to content

Page Views not working...


subhomoy

Recommended Posts

Hiii i got a image hosting script but the problem i'm not able to solve is that in the show image page, the page views counter is not showing unique views. If we refresh the page 100 times from same ip, it shows (views=100)...

Can any one help me with it... The views are stored in the database of the respective users...

can anyone help me to get unique views per 24 hrs per ip....

The code is...

//UPDATE VIEWS COUNT AND LAST ACCESS DATE

  $views = $row['views'] + 1;

  $access = date("y-m-d");

$r = mysql_query("UPDATE `images` SET views = '$views', access = '$access' WHERE id = '$id' ");

 

 

  $imguserid = getUserId($id);

 

  $own = false;

  if ($imguserid != -1) {

     

      if ($userid == $imguserid)

          $own = true;

 

      $r = mysql_query("SELECT username FROM `members` WHERE id = '$imguserid'");

      $row1 = mysql_fetch_row($r);

      $username = $row1[0];

  }

  else $username = "Anonymous";

 

 

 

  echo "<center>";

  echo "<br><LABEL id='title'>Views:</LABEL> $views";

  echo "<br><LABEL id='title'>Date Added:</LABEL> {$row['date']}";

if needed i can supply the full script to the person who can help me...

You can check the demo in [ http://torrentz.0fees.net/wussa/show-image.php?id=c7693c02c3ad2fafe5f5d3f00263a68a ]

 

The full page is attached below....

Link to comment
Share on other sites

if you want to distinguish between views per I.P. address you'll need a table with

 

IP

datetime

imageID

 

And make IP / imageID a composite primary key and use a INSERT ON DUPLICATE UPDATE query which will update the view datetime and just leave one view per IP

OR you can have a unique auto_increment primary key and store every image view and then use a mysql query to select distinct

Link to comment
Share on other sites

if you want to distinguish between views per I.P. address you'll need a table with

 

IP

datetime

imageID

 

And make IP / imageID a composite primary key and use a INSERT ON DUPLICATE UPDATE query which will update the view datetime and just leave one view per IP

OR you can have a unique auto_increment primary key and store every image view and then use a mysql query to select distinct

Can you please give the source code.....

Link to comment
Share on other sites

//here's the sql to count distinct views for the current image
SELECT COUNT(DISTINCT ip) as `count` FROM `imageViews` WHERE imageID='$currentImage';

//each time someone views the image, run a sql code to store their IP address, the time/date and the imageID in the sql table.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.