mybrainhurts
mybrainhurts

Reputation: 25

Php session variables - seeking input for proper direction

I am initially seeking guidance to make sure I go in the right direction. From there I will come back with the code and ask for further assistance. I realize it isn't cool to say "hey I dont know what I am doing so I want you to do it for me."

So, here is my situation. I would say my php skills are amateur, and I am looking to increase them by working on projects for myself so I can learn through practice and application. I have created a webpage which contains a form that is used to update a XML file (I am playing around with flatfile DBs at the moment). All works well, the file is updated and the users is brought back to the page and the updated file is displayed. What I would like to do is allow the user to receive an update while they are browsing the website that the XML file has been updated, as well as alert them to the file update if they are returning to the website after having left.

My thoughts are that this would be done by using php session variables, one when they first access the website and another when the XML file is updated by a user. For the one when they access the site I thought a variable with a unique ID and timestamp as well as a timestamp of the files lastmodified value. I realize that this requires keeping storage of the session values since the value will have to be compared to something or else it will always appear as the most recent version, hence no changes.

Now that I think about it I guess you wouldn't need a session variable created on file update since the comparison will be based on the lastmodified value.

Just want to know if I am on the right track or completely off-base.

Any input is greatly appreciated.

Upvotes: 2

Views: 148

Answers (1)

edorian
edorian

Reputation: 38981

Storing the lastModfided value

For your specific case I hope i understood you right. You want to say "notify the user if he wasn't the last one to work on the file" right?

That should be easily doable using the session as after writing you could store the last modified date of the file in the session and them compair that when the user comes back. I don't see any issues with that approach.


If you have you users log in I'd much rather tie the notification to their accounts.

Your session files will be deleted if the user is way for to long and a new one will be created if he uses a different browser. So it would be a really instable way of giving notice.


For the notifications no matter where he is on the site

If your database is updated in the background and you then could like to create a notification for the user I'd advice again using the php session for that.

While you are able (using some rather ugly hacks) to edit the session files they are not a stable enough basis to implement a notification system.

If you just work of session cookies then I'd still just store a "notify this session id if the guy shows up again" somewhere and check those notifications on every page load.

I know this is not as performant/nice/cool but it shouldn't really matter and save you a lot time dealing with.


Hope i understood you right and it makes sense to youu

Upvotes: 1

Related Questions