floppydrivez Posted July 28, 2007 Share Posted July 28, 2007 I need to check to make sure a user doesn't load the same page twice. I was thinking cookies, but soon came to learn that was not going to work. I am looking for some fresh thought. This is what doesn't work haha $url = base64_encode($_SERVER['REQUEST_URI']); setrawcookie("urlcookie", $url); if($_COOKIE['urlcookie'] != $url){ points(13); } Any thoughts? Quote Link to comment Share on other sites More sharing options...
tibberous Posted July 28, 2007 Share Posted July 28, 2007 End your script with: @unlink($PHP_SELF); Quote Link to comment Share on other sites More sharing options...
floppydrivez Posted July 28, 2007 Author Share Posted July 28, 2007 Hmm... draw it out for me. I am sorry why would I do that? Quote Link to comment Share on other sites More sharing options...
tibberous Posted July 28, 2007 Share Posted July 28, 2007 To keep them from loading the page twice It was a joke. Quote Link to comment Share on other sites More sharing options...
floppydrivez Posted July 28, 2007 Author Share Posted July 28, 2007 Haha, sorry I thought that sounded off. I have little hair or sense of humor at the moment. I know this is possible. I just can't reason with my brain on the solution. Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 Umm maybe you could have a database table e.g. MySQL storing the IP addresses that viewed the page. Make a table like this perhaps CREATE TABLE `viewed_page` ( `page` int(5) NOT NULL default '0', `ip` int(12) unsigned NOT NULL default '0', PRIMARY KEY (`ip`), ) ENGINE=InnoDB; Then insert the user into the table on viewing unless they exist already but first get their ip $link = mysql_connect($server,$username,$password); mysql_select_db($database); $ip = $_SERVER["REMOTE_ADDR"]; $res = mysql_query("SELECT ip FROM viewed_page WHERE page = '$page' AND ip = INET_ATON('$ip')"); $row = mysql_num_rows($res); if ($row==0){ mysql_query("INSERT INTO viewed_page(page,ip) VALUES ('1',INET_ATON('$ip');"); mysql_close($link); }else{ //previously viewed die("Been here before..."); mysql_close($link); } Quote Link to comment Share on other sites More sharing options...
floppydrivez Posted July 28, 2007 Author Share Posted July 28, 2007 This is where it gets complicated lets say the visit home, then home again. I don't wanna update the second home, but I do the first. Easy enough. They visit home, downloads, home. I need to update each one. Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 28, 2007 Share Posted July 28, 2007 Umm yea thats what my script will do, if you simply change the page value for each different page you have this on. Just put visited_before($pagenumber); on the protected page with this function at the top. function visited_before($page){ $link = mysql_connect($server,$username,$password); mysql_select_db($database); $ip = $_SERVER["REMOTE_ADDR"]; $res = mysql_query("SELECT ip FROM viewed_page WHERE page = '$page' AND ip = INET_ATON('$ip')"); $row = mysql_num_rows($res); if ($row==0){ mysql_query("INSERT INTO viewed_page(page,ip) VALUES ('1',INET_ATON('$ip');"); mysql_close($link); }else{ //previously viewed die("Been here before..."); mysql_close($link); } } Quote Link to comment Share on other sites More sharing options...
floppydrivez Posted July 28, 2007 Author Share Posted July 28, 2007 Wait with a little mod I think thats it!! Quote Link to comment Share on other sites More sharing options...
tibberous Posted July 28, 2007 Share Posted July 28, 2007 test.php <?php header("Location: test2.php?key=".md5(time())); ?> test2.php <?php if($key == md5(time()) || $key == md5(time()+1) || $key == md5(time()+2)){ echo "Here is the page!"; } ?> Quote Link to comment Share on other sites More sharing options...
floppydrivez Posted July 29, 2007 Author Share Posted July 29, 2007 Man this snipplet making me sick. Anyone know why this doesn't work. I need to compare the current page to the last page on ever page. session_start(); $url = $_SERVER['REQUEST_URI']; if($page = ""){ $page = '/'; }else{ $page = $_SESSION['views']; } if($url != $page){ update(13); } $_SESSION['views'] = $url; It works, but it seems to take it 2 page views of the same page to update like it should. Quote Link to comment Share on other sites More sharing options...
floppydrivez Posted July 29, 2007 Author Share Posted July 29, 2007 Ah the thing that was actually counting the update came before my custom code. Therefor giving the appearance that it wasn't updating. Gah is all I gotta say. After figuring that bit out. SESSIONS and mysql table works like a charm. Quote Link to comment 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.