Stop people view page more then once?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Stop people view page more then once?

Post by Mr. Tech »

Hi!

How do i stop people from viewing the SAME page at the SAME time? For example:

1. They go to http://www.mydomain.com/once.php

2. It would open and show all the info of the page.

3. If they open up another browser window and go to the same page (http://www.mydomain.com/once.php), it will write in the browser window "You can only view this page once at a time".

How could i do this?

Thanks,

Ben
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Would need some kind of user registration/login/authentication system in order to identify users making a second call for the page.
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Any idea where I can get one?

Maybe I can log their IP into a database.. but some IPs are the same...

Cookies could work but it might interfere with it...

Any ideas?

Thanks..
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

you can try using session cookies.. offcourse it also depend on user brwoser setting. also you can try using no-cache meta tag, and logging a IP.. well not exactly IP. what you can do it.. using the IP and some random generated string, create an unique string.

Let's say user's IP is 200.35.2.110, then we use that IP and add some random generated string, it will be something like "200352110xpbr99ie6".. I hope you get what I mean...
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

How will it remember the generated string?

JavaScript may have to be the way to go... I can use php to hide it :D
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Take the idea of a Online Visitor Counter (you know, "There are now 14 people browsing this site"). There are many snippets of those out there that might be of use to you in this matter.

Slightly take the ideas from one of those, rewrite it some.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

Simple... what i meant by using the Ip+string is instead of logging the IP to database use this string instead.. this solves problem of similar IP's or people who are on dynamic IPs... also you can use cookie to mark the computer... let's say session cookie is good to use since most of the browsers doesn't block it..(unless user have made such setting) but session cookie can be used in conjuction with IP+string logging or as failsafe option...
Sinnix
Forum Commoner
Posts: 43
Joined: Mon Apr 28, 2003 11:01 am
Location: Ottawa, ON Canada
Contact:

Post by Sinnix »

I think this link might help you out some. It's an article about manually expiring web pages in php: http://www.phpbuilder.com/columns/clark20030702.php3
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ok.
here''s one for you ( a hypothetical)
hat happens if i view it
something happens to crash my computer
5 min later (i'm on a lan so i have a static ip) i get back up and try ti view
it already started to load
how does it know i don't already have it open?

anything you do here is flawed. some pteople don't like looking at things in frames. but if you set it up to stop that you kill legitimate reasons to bring it back up as well.
User avatar
SantaGhost
Forum Commoner
Posts: 41
Joined: Mon Sep 15, 2003 11:54 am

Post by SantaGhost »

i dont think its possible with php, you can put a time of for example 5mn where the ip in question cant view the page after the first view, i think you best bet on this is javascript.

maybe something with the onUnload proprety of the body tag, that the page wont be viewable for the person until onUnload has been triggered

onLoad->block ip
onUnload->release ip
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

SantaGhost wrote:i dont think its possible with php, you can put a time of for example 5mn where the ip in question cant view the page after the first view, i think you best bet on this is javascript.

maybe something with the onUnload proprety of the body tag, that the page wont be viewable for the person until onUnload has been triggered

onLoad->block ip
onUnload->release ip
Why not use header()?
If the blocked ip (or whatever being used to determine the visitor status) just header() him/her to somewhere else...
m3rajk wrote:but if you set it up to stop that you kill legitimate reasons to bring it back up as well.
Very true, something worth thinking of. I have had my inet-connection break while i clicked a link on this forum. It got registered as "read" in my cookies, but I never saw the page (not until my connection went back up that is).

I can only think of one good purpose, and that is if you are displaying sensitive data (ie. "Your password is...") or something similiar.

Mr. Tech, could you explain more about the usage of this?
Last edited by JAM on Mon Sep 15, 2003 3:34 pm, edited 2 times in total.
User avatar
SantaGhost
Forum Commoner
Posts: 41
Joined: Mon Sep 15, 2003 11:54 am

Post by SantaGhost »

yes offcourse header("Location:") can be used to redirect to another page, i was thinking in someting of the following:

Code: Select all

<?php
if(status==unblock){
unblock(ip);
$unblock = "onLoad="window.close()"";
}else{
    $blockstatus
    if(blocked){
        header(location)
     }
     block(ip);
}
?>
<html>
<body<? echo $unblock ?> onUnload="top.location.href=?status=unblock&ip=ip">

</body>
</html>
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Hi guys!

Does session_start(); only last for how long you are in the browser window? Once you close it it doesn't exist anymore?

My main problem is this window I am trying to proctect from being viewed twice is a surfing window. You get points for viewing websites and after a certain amount of time the page refreshs with a new page to browse through (Uses frames...)

That stuffs up using cookies I think because if the page is refreshed it will say it can't be viewed...

Any ideas?
Post Reply