One Way or Another!

27 09 2014

flickr: by Wiertz S├ębastien


I recently dusted off an old tome among my PHP books, PHP and MySQL Web Development (1st edition) by Luke Welling and Laura Thomson, a book whose massive length of more than 800 pages would suggest that discarding it might be foolhardy, even though it covers PHP4 which is long gone to ElePHPant Heaven.  However, browsing w3techs statistics this September 2014 revealed that 2% of the websites whose server-side languages they know about, still use or at least have installed PHP4.  Perhaps I should retain the dated book just in case I get the rare client who refuses to upgrade to PHP5.

As I settled in to review the book, this time starting at the end, to see if I might have possibly overlooked something during that crazy time known as the Dot Com Boom, chapter 30 “Generating Personalized Documents in Portable Document Format” caught my attention with the following intriguing remark:

“RTF does not allow us to make a read-only document.”

The statement implies that other file formats do allow adding such a restriction. Curious to see if anyone else had an issue with the statement, I scoured the Internet for the errata page until I found the link tucked away in the waybackmachine. Amazingly, no one had officially complained about the misleading remark and the time to do so is apparently well past.

Making a document read-only typically involves the operating system although you may do this with PHP (see for files residing on a Linux or Unix based operating system. For windows, one would need to use PHP’s system() or exec() function together with the windows attrib utility (see discussion at Markup languages like HTML and Microsoft’s rich text format (RTF), of course, have a more narrow purpose, focused on how the content should display, including the fonts, colors, images, text size, etc.

I discovered with WindowsXP that “protecting” an RTF File with MS Word 2003 assures the user that the file is read-only while nothing of the sort happens! While the document was “protected” from being overwritten in MS Word, once I quit the program and checked the file’s attributes, they revealed that it was not restricted to read-only status. I easily opened it in WordPad, NotePad, NotePad++ and nothing prevented me from making changes and saving the document. In order to properly make the file read-only, I had to right-click on the file in a directory listing and select properties from the popup menu, and then check “Read-Only” at the bottom of the General Tab’s attribute choices.

Read-Only in Windows, unlike its counterpart in Linux,  pertains to the concept of file attributes whereas Linux deals with file permissions. Designating a file as read-only in Windows means it will be that way for everyone who views the file. In Linux a file may be read-only for the owner, a group or all users. In fact, in Linux one can even restrict who may view the file. If one sets the permissions to “000”, then only the special user known as Root may view it (see

Once I had made the file read-only on Windows, everything worked as it should. Regardless as to which editor I used to open the file, the operating system would not allow me to modify and save the file. But, you may circumvent this restriction by saving the file with a different file name. On Windows, read-only is not a way to secure a document but rather a way to prevent one from inadvertently changing the document. In Linux, a similar counterpart exists with VIm and “view” mode.

I next wondered what would happen if I transported my read-only RTF file from Windows to a Mac environment. OS X (10.9)  immediately responded with a message asking if I wished to unlock the file. Once unlocked , I was able to modify the document.

I did one more experiment by creating an RTF file in MS Word on a Mac running OS X (10.9) and protected it. The protection worked as long as I attempted to edit the file within MS Word but as soon as I closed the application and attempted to edit the file with TextEdit, just like on Windows, all that protection vanished. So, I attempted to manually make the file read-only by “locking” it. That effort paid off and then some. On the Mac it stayed in read-only mode as I had expected. When I transferred the file to WindowsXP, the operating system complained that the file was read-only when I tried to change it.

What can we infer from the preceding? If you wish to restrict someone from intentionally tampering with a file the Protect feature in MS Word is of limited usefulness since one may bypass it by merely opening up an RTF file in a different editor. If you’re mainly concerned about preventing yourself from accidentally changing the content, then you should “protect” your MS Word documents.

I am pleasantly surprised and delighted that one may take a “locked” RTF file from the Mac, transfer it to WindowsXP and despite its age WindowsXP understands and respects that the file is read-only. Seems a shame that WindowsXP is no longer supported when it certainly stands out as one of the better versions of Windows in contrast to the previous Windows 2000 and the subsequent Windows Vista.

This work is licensed under a Creative Commons License




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: