Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i make sure that a page is opened by only one user?

Status
Not open for further replies.

anotherday

Programmer
Jan 17, 2001
9
0
0
AE
THE PROBLEM:

I have a page called (update.cfm). I don't wanna allow more than one user to open that page at the same time from anywhere in the world.

The page consists of some fields (text boxes) and two submit buttons (Update, and Cancel). I tried to use a field called (InUse) as the following:
When someone opens that page, the field 'InUse' will hold the value 1 to denote that the page is in use by someone. And when that one clicks Update or Cancel, the field will hold the value 0 to denote that there is no one uses the page now. But the problem is that the user can use the X button to close the website directly, and then the field will be holding the value 1 instead of 0.

Can you help me to do that?
 
I don't have an immediate solution to your problem (although I think you could work with a combination of cookies and session variables), but I wonder why you want to do this. If preserving the integrity of your data is your main concern, you could opt for using <CFLOCK> around your code where you UPDATE your database. Plus check if the data has changed in the meantime.
Maybe you can be more specific why you want this, since I think it's not such a good idea to do on a website.
Regards...

<webguru>iqof188</webguru>
 
I want to make sure that only one user is updating some record in the database...so each record has an id...if that record is in use...some other field will be set to one...to garenty no one is updating the same record at the same time...and when that user clicks a button (update,save,cancel) the value in the field will set to 0
but if the user clicks the X(close window)...how can I control that...
Regards...
 
If you're trying to make this like source control where someone &quot;checks out&quot; a record from the database, I can offer something that might work. Whenever someone loads the information on the page to start the update, create an application variable called &quot;lock#recordIDNumber#&quot; (where recordIDNumber is your unique key) and set it equal to the current time #now()#. Also, create a second application variable called &quot;user#reocrdIDNumber#&quot; and set it equal to &quot;#cfid##cftoken#&quot;. You can then define a time period they have to make an update in such as five minutes ( a checkout period). Every time someone attempts to update a record, check for the existence of an application variable &quot;lock#recordIDNumber#&quot; and see if the time difference is greater than the &quot;checkout period&quot;. If it is, reset it to the current time and update the &quot;user#recordIDNumber&quot; to their cfid &amp; cftoken. Whenever the update is to occur, check to make sure the variable &quot;user#reocrdIDNumber#&quot; is equal to their cfid &amp; cftoken combination. If it is, then it's either still within their check out period OR their period has expired but no one else has attempted to check it out. In either case, update the record within a <cflock>. If however their cfid &amp; cftoken don't match the &quot;user#recordIDNumber#&quot; application variable, it means someone else has the record for updating and you just supply an error message saying they took too long.

You will want to use a <cflock> with the same name around the section that &quot;checks out&quot; the record and the section that does the update.

Good luck,
GJ
 
Good solution to the technical problem GunJack, but don't you agree it is very tricky to do something like this? :) <webguru>iqof188</webguru>
 
Yea, you have to make sure you're careful with your locks and any changes you make later but I think it's feasible. A different application design might make this kind of trickery unnecessary though which would be the best route imo.

GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top