CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Remember chosen language (with cookie?!)

Print topic Send  topic

Author Message
Headhunter
Posted: 04/27/2003, 2:20 PM

Project: PHP + MySQL

I have created a multi language site with 3 different languages.
When a user comes for the first time to the page (index.php) he must choose a language. I created 3 links and added a paramater "lang=1" for dutch, "lang=2" for french and "lang=3" for english.

Now what I want to do is when a user returns, he must be redirected to the homepage of the website in the desired language he has chosen the previous time.
There must also be a link to change language at any time.

Thanx.
Headhunter
Posted: 04/30/2003, 1:48 AM

Anyone?
Hamilton
Posted: 04/30/2003, 10:22 AM

The cookie is not necessary and many have them turned off anyway.<br>
Why not pass the ?lang=1 in the URL/Querystring from page to page?
Headhunter
Posted: 04/30/2003, 3:30 PM

Hamilton,

you misunderstand the problem. I do pass the "lang" parameter. It is just when the user comes for the first time to the website it come on the page index.php where he/she select a language. Now, I want this to rememer so when the user visit's the website again, it should directly redirected to the homepage (which is "main.php") of the website in the previous chosen language.

Check it out and you'll see what I mean at:

http://www.geecocars.be
Hamilton
Posted: 04/30/2003, 4:19 PM

Now I understand.

Basically, you don't have much choice if you want the user's machine to remember the language setting. You must use a cookie. You were right.

But that will have it's own issues.

Anyway, I don't know php well enough to provide the code for the cookies, but - I can give you some of the logic - wherein you can plug-in the cookie code. So I'll write it in a sort of psudo-language that hopefully will be easy to follow.

You probably know this logic already and I mean no offence by placing an example, but feel bad that I cannot supply a cut and paste anwer and hope not to have wasted your time.

On the landing page showing the 3 languages to select from.
On the Page_After_Initialize event

'// check for the existance of an existing cookie
'// if there isnt one, do nothing.
'// if there is one, leave that up to the home page.
'// update the datetime stamp and expiry date of the cookie
'// automatically redirect the user to the home page

When the user hits the home page (main.php),
On the initialize event
'// check for the existance of an existing cookie
'// if there isnt one, create one
'// if there is one
'// update the cookies language setting
'// done

This way, the landing page really just has to do the check to perform the redirect. and the Home page (that's when we know for certain the language being viewed) writes the language id to the cookie.

If the user then selects another language from a picklist (let's say) when the user clicks 'go' for that language - the page reloads, and seeing that the language id is not the same, updates the cookie with the new setting.

PS. On that image on the landing page [the one after one has selected a language], within the image tag, put this;
galleryimage=no - it'll stop the pic menu from distracting the user when they mouse over it.

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.