how to limit the user access to the page

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
how to make a user management in php, i mean that i want to limit the user
access to my page. the script will not allow 2 user have an access to my
page at the same time. the script only allow 1 user to access the page.
the second user will have the queue massage. please help me ... :)

thank's before

Re: how to limit the user access to the page

indie wrote:

Quoted text here. Click to load it

Sounds like a disaster waiting to happen. This sort of question tells me
you do not really grasped the concepts of what a web page/server really
is and how they actually work...  Each "page" access is autonomous. In
other words, one does not, cannot know about the other because most
webservers are multi-threaded and can also have multiple servers
responding to multiple request concurrently. This would  be like trying
to control the number of water molecules dripping from your faucet.

Now, if you can explain a bit more about what you are trying to achieve,
someone here may have already "been there/done that" and can give you
some pointers.

Two things I can think of would be to modify your server to only accept
one connection at time (in which case user 2-n will go elsewhere) or
check to see if a filename exists (like pagelock.txt - no data needs be
stored in it, merely does it exist) within a particular directory and if
not create it and if it does loop until it disappears, process work,
then delete the file.  However, what happens if two people try to create
a file at the same time... who wins - because the other user also thinks
he created the file unless there are boatloads of status messages as to
the success or failure of the call to create the file, keeping in mind
that Unix and Windows will allow to "overwrite" an existing file.  So
both processes will think they have created it and continue on.  You can
really never say that this scenario can't happen, but in the real world,
it not only can happen, but probably will -- and how will that affect
your processing?

You need to reconsider the design rather than the "fix" for your little

Michael Austin.

Re: how to limit the user access to the page

Hi Indie, Hi Micheal,

Interesting puzzle.

Michael Austin wrote:
Quoted text here. Click to load it

I guess Unix won't do that if the file is still open for writing.

Now if the first process first tries to open file 1 for writing and
keeps it open, then checks for file 2 to exist. If it does not, it it
creates it. Then closes file 1.

If a second process tries to do the same at aprrox. the same time, it
should either get an error for file 1 to be open for writing by an other
process, or it should find file 2 to exist.

But maybe this is overkill, it's like two phase commit, that is used for
distibuted transactions. Maybe your data is in a single database. If you
use a database that supports transactions, you should be able to SELECT
the page's record FOR UPDATE and set a boolean in its 'locked' column
and COMMIT WORK without have to worry about another process trying to do
the same at approx the same time. Newer MySQL for example versions
support this if you use the right type of table. You may have to set a
transaction isolation level to the database or table. OK, this may after
all be more complicated then those files, but OTOH, you may learn a
thing or two about transaction isolation, commit and rollback.


Henk Verhoeven,

P.S. There can be a similar problem with the back key of the browser,
caching and proxies. It may prove impossible to make sure the page is
not reshown from a cache. And are you sure the form can not sucessfully
be resubmitted after an other user has established a lock?

Re: how to limit the user access to the page

indie wrote:

Quoted text here. Click to load it

Not exactly something easily done through the web. I have a couple ideas
that may work, but you'd be better off doing this through some kind of
Java applet. Anything that doesn't talk to both the server and client
machines in real time will pose quite a few problems with timeouts and
page locks.

Justin Koivisto -
PHP POSTERS: Please use comp.lang.php for PHP related questions,
              alt.php* groups are not recommended.

Re: how to limit the user access to the page

actually i made teleoperation system that controlling my servo motor from
remote area. ofcourse only 1 user have an access for that, and the second
user can't will not have it.if both of them have an access at the same
time, my motor will "confuse" and can't move properly.

Re: how to limit the user access to the page

Quoted text here. Click to load it

Give each on-line user a UID and store them in a table.

(Table structure: id, userid, incontrol, updated)

Each time the page loads check "incontrol".  If all set to FALSE then output
a button on the control page to allow a user to take control.
Check when posted that all "incontrol" are all still set to FALSE, then set
the active user to incontrol = TRUE.

If current user is incontrol then output a button to allow the user to
relinquish control (incontrol = FALSE)

"updated" as a timestamp will allow you to delete any users that are
inactive for a while, (stops someone taking control indefinitely).

That's about it.

Re: how to limit the user access to the page

Quoted text here. Click to load it

You explained it, but from the original post I am NOT sure they can
understand what is needed. Truth be told, I don't think the original
user is even checking this site to see if their question is being

BUT if they are...
The way I would try to explain it is like this.

You need a permanent db/file-based option for what you want.
You need someway for THAT page to check to see if someone else has it
Every time that page opens, it should check.
"Am I already opened?
If I am already opened, then don't open for this new guy.
If I am NOT opened, then open and note in the db/file that I am now
If I am already opened? I should also check:
How long have I been opened?
If I have been opened longer than allowed, then note in the db/file
and close.
If I have been opened less than I am allowed, stay opened."

THAT should cover it...
I think...

I just recently started work on a personal CMS.
The User Authentication is the hardest part.
How do you register users as still signed in?
Difficult, but not impossible.
I finished my user authentication and am now working on HTML

Re: how to limit the user access to the page

thank's guys

Site Timeline