Jump to content

Little code for views & refresh


alwaysme

Recommended Posts

hi

 

this is some script i got from hotscripts.com.. what i need is for the views to change with refresh. what it has now is baised on IP ...im not very familiar with php, but i presume this is the file that controls the views..can anyone alter it so it doesnt record the views baised on IP's and incriment with a browser refresh?

 

 


$id = $_GET["id"];

if(!isset($_COOKIE[$id])){
$twomonths = 60 * 60 * 24 * 60 + time();
setcookie("$id", $id, $twomonths);
$viewaddone = true;
}

require('header.php');

if(isset($id)){
$result = mysql_query("SELECT * FROM pp_files WHERE id=$id LIMIT 1") or die();  
}elseif (isset($_GET["name"])){
$name = $_GET["name"];
$result = mysql_query("SELECT * FROM pp_files WHERE `approved` = '1' AND `name` = '$name' LIMIT 1") or die();  

}else{
$result = mysql_query("select * from pp_files WHERE approved='1' AND reject='0' order by rand() LIMIT 1") or die();  
}
// For each result that we got from the Database
while ($row = mysql_fetch_assoc($result))
{
$video[] = $row;

        if($viewaddone == true){
                $new_views = $row["views"] + 1;
                mysql_query("UPDATE pp_files SET views = '$new_views' WHERE id = '$id'");
        }

$smarty->assign('vidtype', $row['video_type']);

if( $row['video_type'] == "dailymotion"){
$dm_xml_pic_string = @file_get_contents("http://www.dailymotion.com/atom/fr/cluster/extreme/featured/video/".$row['file']);
$dm_xml_pic_start = explode("/swf/",$dm_xml_pic_string,2);
$dm_xml_pic_end = explode("\"",$dm_xml_pic_start[1],2);
$dmid = $dm_xml_pic_end[0];
$smarty->assign('dmid', $dmid);
}
}

// Assign this array to smarty

$smarty->assign('video', $video);
$smarty->assign('id', $row['id']);


if(isset($_GET["pop"])){
$smarty->display('viewvidpop.tpl');
}else{
$smarty->display('viewvid.tpl');
}

mysql_close($mysql_link);
?> 

 

thanks so much

 

Link to comment
Share on other sites

Just store the #pageviews in the DB, and then every time the page is opened, query the DB for that value then take the value and increase it one.

 

It already does that..

if($viewaddone == true){
                $new_views = $row["views"] + 1;
                mysql_query("UPDATE pp_files SET views = '$new_views' WHERE id = '$id'");
        }

I don't see anywhere where getenv("REMOTE_ADDR") is defined...

Link to comment
Share on other sites

Again, like I said, in the code that you posted, there is nowhere that $_SERVER['REMOTE_ADDR'] or getenv("REMOTE_ADDR") is defined. Unless it's somewhere else in the code that you didn't post.


if($viewaddone == true){ // It is, see Line 7
                $new_views = $row["views"] + 1; // "views" column was selected on 12, 15 or 18
                mysql_query("UPDATE pp_files SET views = '$new_views' WHERE id = '$id'"); // Update the previously selected "views" column by +1
        }

 

 

Link to comment
Share on other sites

$_SERVER['REMOTE_ADDR'] gives the IP of the user, all I'm saying is that in the script you posted, no where does it get the user's IP, and therefore it's impossible (from what you posted) to give the view count off the user's IP address. All it does is fetch the view count from the DB and increase it by one.

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.