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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.