Jump to content

[SOLVED] Old page vs New Page


floppydrivez

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/62141-solved-old-page-vs-new-page/
Share on other sites

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);
}

 

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);
}
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.