View Full Version : customized user's personal page using sessions?

03-28-2003, 01:18 PM
so far in php i've only worked with database interaction and ordinary programming, so i don't know much about sessions, cookies, http_...stuff etc.

i'm doing a site where registered users get to choose their custom css style for the site, work on language lessons, take tests and exercises, etc. whenever they log in they can go to their own user page and everything here should be customized according to themselves; the site style (colors, etd), a link to the lesson they're currently studying, a link to their past performance, a link to a list of threads they're subscribed to in the site's forum (pretty much like here at CF), a link to .... you get the idea.

for one thing, i'm not exactly sure what would be right to use, cookies or sessions, or both:confused:. by reading previous threads i guess i'll be using sessions.

but the main problem is how can i go about tracking the user's activity so that i know which page he/she left off on last time, so that when he/she logs in again, there should be a link to that particular page? what i can think of so far is that every page should have a session_start on top and should register the user on it, then when the user closes the browser, the session stores the page he was on that was closed, to get inserted in the database.
like for eg, if A signs in and goes to page1, the session "username" will be registered with value "A" and variable "curr_page" will also be registered and will update the A's 'curr_page' column in the database. then, when he goes to page2, "curr_page" will change and update the database again. and so on until the user simply disconnects or closes the browser window.
that's what i can think of so far, no idea if it's the right approach. any suggestions?

03-28-2003, 01:29 PM
here is how i would do it :)

i would create a header.php that you include on every page. In this page you would start the sessions, etc etc. You would also have a mysql query that updates the users location into the database so basically it records where the user is going, not where they were before they left. IT gets tricky recording the location AFTER people have left your site :P

In reguards to "sessions or cookies?" a simple way to look at is:

cookies are insecure yet last longer. sessions are more secure but dont last as long.

You could use a combination of the two. :)

WOW! i hope that all made sense :D

03-28-2003, 04:54 PM
You will want to use sessions to keep track of their current progress.

As for saving where they left off I would include a "Save your progress" button. If they just close the browser there is no way to save what they have done so you should make it known to them that they need to save their work before they leave if they wish to start from where they left off.

03-28-2003, 11:56 PM
i dont think many people would bother clicking the 'save' button :D

It should be automatic.

03-29-2003, 03:20 AM
if every page updates the database then it does not matter if the user closes the browser window without saving.

Remember all your server-side processing is done well before the user gets to see the page, so if in your scripts you make sure that the last thing you do in your script is save the session data to the database.

//do your stuff//
<? save_session_data();?>

if you dont want to crawl through your code adding the function you can utilise .

function save_session_data(){
echo "this will be called when all other processing is complete";

note that register_shutdown_function() is ropey on windows

03-29-2003, 05:53 AM
Well once the page has already loaded and then they do some work the data cannot be saved automatically before they close the browser. Another request to the server would have to be made. I've seen other sites where l've filled out long applications and they provide a save feature so you can come back later. They even pop up an alert every few pages to remind you to save your work.

03-29-2003, 06:43 AM
yes for forms etc , I thought this was just tracking users around the page / and or personalised settings ?

They even pop up an alert every few pages to remind you to save your work.

not via a talking paperclip I hope ;)

03-29-2003, 04:08 PM
Originally posted by firepages
yes for forms etc , I thought this was just tracking users around the page / and or personalised settings ?

not via a talking paperclip I hope ;)

He had mentioned taking tests and doing exercises and stuff so I would assume the use of forms.

I hate that talking paperclip dude. :cool: