Jump to content

cookie/session to change lang


rev

Recommended Posts

I have a cookie :D

 

This cookie stores a value that i use to set the language on my website (not whmcs). It can be en (english) and de (german). I want to use this cookie to set language also on whmcs. As far as i know whmcs uses session for languages. The session should be $_SESSION["Language"] and can assume English and German values.

 

How can i mix them? I tried with something like:

if ($cookie = "en") { $cookie = "English"; }
if ($cookie = "de") { $cookie = "German"; }
// now values are equal

$_SESSION["Language"] = $cookie;

But it doesn't work and i think because there's a problem with session_start() since with the above code i'm in header.tpl (included). I tried also with session_destroy() with no success.

 

Any idea?

Link to comment
Share on other sites

Where are you trying to use this code as if it is within a .tpl file the code it's self will not work and if it is PHP then the this may do it:

if ($cookie == "en")

{

$cookie = "English";

}

elseif ($cookie == "de")

{

$cookie .= "German";

}

// now values are equal

 

$_SESSION["Language"] = $cookie;

 

OR

unset ($_SESSION["Language"]);

if (!isset ($_SESSION["Language"])

{

if ($cookie = "en")

{

$_SESSION["Language"] = "English";

}

elseif ($cookie = "de")

{

$_SESSION["Language"] = "German";

}

}

else

{

echo 'session is still set so this is not working! ';

}

Edited by thehost5968
Link to comment
Share on other sites

The code i posted was on the fly just for the post. I'm not using that code. Anyway back on topic now i understand why it's not working.

 

On example.com i setcookie("language","en",time()+60 * 60 * 24 * 180,".example.com"); then on whmcs.example.com (i've whmcs on subdomain) i

$cookie = $HTTP_COOKIE_VARS["language"];
echo $cookie;

And the result of the echo is empty :? Why can't i pass cookies to whmcs?

 

p.s. yes, of course, as i already said, i have this script included in the header

Link to comment
Share on other sites

On example.com i setcookie("language","en",time()+60 * 60 * 24 * 180,".example.com");

Damn it :!: Little oversight :mad: it's setcookie("language","en",time()+60 * 60 * 24 * 180,"/",".example.com");. That's why it wasn't working.

 

I must stop going by memory when i write php.

Edited by rev
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated