Trolleri Posted May 30, 2009 Share Posted May 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/ Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 Lock the file when someone requests to write to it. flock Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/#findComment-845383 Share on other sites More sharing options...
Maq Posted May 30, 2009 Share Posted May 30, 2009 Is this an actual file, or an entry in a database? Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/#findComment-845399 Share on other sites More sharing options...
Trolleri Posted May 30, 2009 Author Share Posted May 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/#findComment-845647 Share on other sites More sharing options...
Trolleri Posted May 30, 2009 Author Share Posted May 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/#findComment-845959 Share on other sites More sharing options...
Trolleri Posted May 31, 2009 Author Share Posted May 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/#findComment-846420 Share on other sites More sharing options...
Trolleri Posted June 2, 2009 Author Share Posted June 2, 2009 Nevermind! If lockfile has been locked for more than one hour, the script resets lockfile, and goes back to editting the txt-file. flock() could not be used for me. Quote Link to comment https://forums.phpfreaks.com/topic/160215-solved-how-to-restrict-edit-access-to-a-value-so-only-one-person-can-edit-at-a-time/#findComment-847662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.