homepage Welcome to WebmasterWorld Guest from 107.21.163.227
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Cookies not saving on certain machines
Tom_Cash




msg:4350689
 8:33 am on Aug 12, 2011 (gmt 0)

Hi All,

I not long back launched a new multi-lingual website for our business. I did thorough testing before it's launch, however, after another branch in the business had some new machines installed, their website is not remembering their language settings.

They have a Spanish IP address so there website renders in Spanish. But when the staff set their language to English the browser will forget their preference upon close.

The older machines within the branch will remember the cookies as normal. But these new ones are presenting a problem.

I tried altering the browser settings in IE and Firefox and I even downloaded Chrome to try that.

Nothing.

My iPhone on their IP has no issues remembering the language.

Just these new machines...

Is it at client level, or is there any way this could be an issue with my coding?

My PHP code is as follows (I've removed a lot of repeating ifs - but the code is mainly the same):


<?
// THIS PAGE ASSIGNS A LANGUAGE
// THIS PAGE HAS NOTHING TO DO WITH THE CONTENT THE USER SEES - ONLY THE LANGUAGE THEY SEE IT IN

// IF COOKIES ARE AVAILABLE...
if (isset($_COOKIE['PHPSESSID']))
{
// AND ONE ISN'T SET, SET ONE
if(isset($_COOKIE['Language_Preference']) == FALSE)
{
// SET COOKIE EXPIRY TIME
$number_of_days = 1825; // APPROX. 5 YEARS (ON THE LOGIC THAT PEOPLE CHANGE THEIR PC AROUND EVERY 5 YEARS (MAYBE?))
$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days;

// ENGLISH (UK): UNITED KINGDOM
if($geo == 'GB')
setcookie("Language_Preference", "1", $date_of_expiry, "/", ".example.net");

// SPANISH: SPAIN
elseif($geo == 'ES)
setcookie("Language_Preference", "5", $date_of_expiry, "/", ".example.net");

// ELSE SHOW ENGLISH US
else
setcookie("Language_Preference", "16", $date_of_expiry, "/", ".example.net");

header('Location: http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
}

// SET THE LANGUAGE ID FROM THE COOKIE
$languageid = $_COOKIE['Language_Preference'];
}
// DON'T USE A COOKIE
else
{
// ENGLISH (UK): UNITED KINGDOM
if($geo == 'GB')
$languageid = 1;

// SPANISH: SPAIN
elseif($geo == 'ES')
$languageid = 5;

// ELSE SHOW ENGLISH US
else
$languageid = 16;
}
?>


Any help or insight would be fantastic!

Thanks in advance,
Tom.

 

mipapage




msg:4350711
 10:18 am on Aug 12, 2011 (gmt 0)

Your missing a close ' in your code above. I doubt that is it but... elseif($geo == 'ES)

According to the logic here they should get Spanish if != cookies and a Spanish IP.

Have you tried echoing into the html source the cookie values for one of these users? For all intents and purposes it seems like they aren't accepting cookies...

Tom_Cash




msg:4350716
 10:26 am on Aug 12, 2011 (gmt 0)

Thanks for such a prompt reply!

Sorry, that code error was a result of me trimming it for this forum! Well spotted. ;)

As for the cookies - they are accepting them. That's what is baffling me so much! For example, I visited a competitor who uses a similar arrangement to us and their site remembered my language after a browser close, a restart and an hour later, after a shutdown!

Even my iPhone remembers the language whilst connected to their IP address.

Yet our website does not remember...

I am so confused!

mipapage




msg:4350720
 10:42 am on Aug 12, 2011 (gmt 0)

Okay so the cookies are working, my next guess was that perhaps the clocks hadn't been set on the new machines.

And you have tried to echo the cookies for your site and a PHPSESSID is available?

Tom_Cash




msg:4350768
 2:07 pm on Aug 12, 2011 (gmt 0)

Yeah, I've tried the latter. When I get back over to the branch I'll have to see if the clocks work!

That sounds, to me, like a very good suggestion.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved