Take the 2-minute tour ×

I am going to improve a web site in Apache and PHP which has a page with a table containing a list of files. My goal is to allow the user to set one of those files as the “important” one based on some specific and subjective criteria. In order to do that, I want to store the information regarding the most “important” file in some way, with the restriction that I am able to use neither databases nor files (constraints imposed by supervisor).

My questions are:

  • Is it possible?
  • How can I do this?

I already did a search in this site, but I did not find an answer.

EDIT: By the way, finally I solved my problem using an XML file. Thanks a lot to everyone.

share|improve this question
Your supervisor is an idiot if he expects you to persist data without actually saving it anywhere. –  Martin Bean Jul 26 '13 at 8:25
Please make sure you make your supervisor read the above comment –  Mr. Alien Jul 26 '13 at 8:27
You might want to find a different supervisor .. –  tereško Jul 26 '13 at 8:29
I expect there is a misunderstanding here somewhere - ask the supervisor (work supervisor? or teacher?) which means of storage are acceptable. Is it supposed to be user specific? or persistent? Nobody is likely to willingly ask you to do something that's not possible, unless that's the point of the task - for you to conclude/say it's not possible. –  AD7six Jul 26 '13 at 8:36
Yes, your supervisor is a fool. First, get yourself a job where your 'supervisor' actually wants you to better yourself, but in the mean time, either use sessions / cookies... or memcache / apc (warn the idiot that once the server is restarted, the list of importants are gone). –  Jimbo Jul 26 '13 at 9:12
show 4 more comments

5 Answers

up vote 4 down vote accepted

Assuming these criteria are client-side rather than server-side, because if they're server-side and it's supposed to be one 'important' file for all users then there's no way to do this without storage.

The supposed answer to your solution is localStorage()...

It's Javascript dependent and definitely not a perfect solution, but HTML5 localStorage allows you to store preferences on your users' computers.

First, detect support for localStorage():

if (Modernizr.localstorage) { // with Modernizr
if (typeof(localStorage) != 'undefined' ) { // Without Modernizr

Then set a parameter if it's supported:

localStorage.setItem("somePreference", "Some Value");

And then later retrieve it, as long as your user hasn't cleared local storage out:

var somePreference = localStorage.getItem("somePreference");

When you want to clear it, just use:


For those using unsupported (older) browsers, you can use local storage hacks abusing Flash LSOs, but those are definitely not ideal.

What about sessions or cookies?

Both of these are intentionally temporary forms of storage. Even Flash LSOs are better than cookies for long-term storage.

The constraint is literally encouraging poor practices...

All of these options are browser-side. If the user moves to another PC, his/her preferences will be reset on that PC, unlike with a database-powered authentication system where you can save preferences against a login.

The best way to store this kind of data is in a database. If you can't run a database service, you could use SQLite or store the data in JSON or XML files.

share|improve this answer
Thanks a lot to everyone for your suggestions! Since it is a client side decision which must be propagated to the server side I guess that the answer to my questions is that it is not possible if I am not able to relief the constrints. Thanks! –  pafede2 Jul 26 '13 at 8:56
add comment

Cookies might be helpful. I can't think of any other secure way. This isn't too graceful either.


share|improve this answer
Do you know how much data can a cookie hold? –  Mr. Alien Jul 26 '13 at 8:29
Its 4kb. It should be ample for the stuff you would be using . –  trunks175 Jul 26 '13 at 8:44
add comment

You can persist data temporarily using sessions and cookies. They don't require files or database; However, as mentioned, it is temporary because the data is gone when the browser is closed or the cookie expires.
If you are told to persist data permanently without the use of files or database, your supervisor has already set you up to fail.

Hope this helps.

share|improve this answer
Sessions are typically persisted with either files or a database. Of course, an in-memory database could be used. –  Jack Jul 26 '13 at 8:32
I know; those files are created by the system and not the OP; so, in a way, he's still complying with the requirements. –  Kneel-Before-ZOD Jul 26 '13 at 8:33
add comment

The only options I can see would be to either use cookies (which aren't permanent and are stored as files on the client).

Another option may be to use something like Parse which is allows you to store data in the cloud.

It depends how strict your supervisor is however since the first solution uses (client) files and the latter will be using a database on another server.

share|improve this answer
add comment

You could try using a cookie to store the data

To set the filename use:

    setcookie("important", $importantFileName); 

To read the data use:

    $importantFileName = $_COOKIE["important"]; 

But this wil only work for the current user and other users wont be able to view this.

share|improve this answer
add comment

Your Answer


