alwaysme Posted December 27, 2007 Share Posted December 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83400-little-code-for-views-refresh/ Share on other sites More sharing options...
drummer101 Posted December 27, 2007 Share Posted December 27, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/83400-little-code-for-views-refresh/#findComment-424384 Share on other sites More sharing options...
alwaysme Posted December 27, 2007 Author Share Posted December 27, 2007 sorry but i have no idea how to perform that..... the code above displays the # of views that saw the page baised on IP i just want it to record based on refresh.... sorry im extra novice Quote Link to comment https://forums.phpfreaks.com/topic/83400-little-code-for-views-refresh/#findComment-424387 Share on other sites More sharing options...
drummer101 Posted December 28, 2007 Share Posted December 28, 2007 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 } Quote Link to comment https://forums.phpfreaks.com/topic/83400-little-code-for-views-refresh/#findComment-424391 Share on other sites More sharing options...
alwaysme Posted December 28, 2007 Author Share Posted December 28, 2007 hello again should i look for the statement $_SERVER['REMOTE_ADDR'] in all the files and report back i dont know what you are asking me to do....pelase let me know... this is the script i download https://sourceforge.net/project/platformdownload.php?group_id=183704&sel_platform=2349 Quote Link to comment https://forums.phpfreaks.com/topic/83400-little-code-for-views-refresh/#findComment-424631 Share on other sites More sharing options...
drummer101 Posted December 30, 2007 Share Posted December 30, 2007 $_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. Quote Link to comment https://forums.phpfreaks.com/topic/83400-little-code-for-views-refresh/#findComment-425589 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.