Hi, I am trying to create a website where the visitor can choose one of two languages when first arriving at the website. Then I want that choice to be saved throughout the whole visit without the visitor having to log in. I've always felt that cookies are a lame way of solving things so first I tried out always including the language choice in the url and making sure that the language choice always remained (if not the user switched it) through variables and php redirects if the choice was removed from the url. But it too felt unprofessional so I tried out storing the information in a session and it works perfectly except that I'm trying to create a script that deletes the session variable when the user leaves the site (onunload on the body doesn't work here because then it gets executed when the user wants to view another page of the site and not just when he leaves).

Maybe this is all unnecessary and I should just go with a cookie? Or does anyone have another solution?

Recommended Answers

All 2 Replies

Hi, I am trying to create a website where the visitor can choose one of two languages when first arriving at the website. Then I want that choice to be saved throughout the whole visit without the visitor having to log in. I've always felt that cookies are a lame way of solving things so first I tried out always including the language choice in the url and making sure that the language choice always remained (if not the user switched it) through variables and php redirects if the choice was removed from the url. But it too felt unprofessional so I tried out storing the information in a session and it works perfectly except that I'm trying to create a script that deletes the session variable when the user leaves the site (onunload on the body doesn't work here because then it gets executed when the user wants to view another page of the site and not just when he leaves).

Maybe this is all unnecessary and I should just go with a cookie? Or does anyone have another solution?

Sessions still use cookies. That's how the session data structure in the server's memory is mapped to the user's machine. Here's more on the topic from a daniweb user: http://www.daniweb.com/forums/thread138791.html

Thanks, I guess I'll go with the cookie method after all :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.