Jump to content

[SOLVED] How to restrict edit-access to a value, so only one person can edit at a time?


Trolleri

Recommended Posts

Hi

 

We are 46 people, who wants to help each other with writing one yearbook. Every person will get a page with text, which every person have had the change to fill out, add more or correct.

 

So I want to make a PHP-page, with a list of the 46 persons. When I click on a name, the PHP-page calls the text associated with the name, and also gives the user a form to edit that text in. To avoid any data-loss, when multiple people are editing the same entry, at the same time, I want to restrict the edit-access to one person at time.

 

Is it possible, and will someone help me to get startet?

Link to comment
Share on other sites

It really doesn't matter wether it is a text-file, or an entry in a database.

I was thinking of using Wordpress for it - you can see an example here: www.trolleri.dk/RH

 

But how can I lock the edit-possibility in Wordpress?

Link to comment
Share on other sites

I went to wordpress supportforum, and they told me the following:

If you are editing a post on a wordpress blog, and another user wants to edit the same post, that second user gets a message saying that the post is already being edited - but the post is not at all locked!

 

I have finished a script that allows everyone to edit 46 textfiles, on my homepage.

index.php -> http://pastebin.com/m2bd58d4f

edit.php -> http://pastebin.com/m6bd366e3

example: http://trolleri.dk/he

The txt-files, as it might show from my code, is located ./pages/page001.txt etc.

 

After this, I have read the information about flock() - thanks Ken2k7

 

But something is going wrong, because the files are not getting locked. Can you help me?

 

Link to comment
Share on other sites

I was able to solve it, without using flock().

I made a lock-file for each txt-file. Then the editing of the txt-file, is only allowed when lock-file is empty. After edit, the lock-file will be made empty.

 

Demo: http://trolleri.dk/HEHE/

 

index.php

http://pastebin.com/m53e7c92d

 

processscript.php

http://pastebin.com/m3efb5551

 

reset.php

http://pastebin.com/m32d469f2

 

And now to the final touch: Is it possible for me to unlock writing to the file, if the user neglects to press "cancel" or "update" when editing. If it is done now, the file is locked, and I need to use script reset.php

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.