I'm sure this topic had been addressed before, but I can't seem to find an adequate solution to my problem, which I'm sure is not unique.
So I get that you can't set a cookie and expect to use without refreshing the page. So I'm wondering what my options are.
I have a simple set of links that change the language on the page by setting a cookie to that user's language preference. I need to detect that cookie to assign a variable so that I can then change the page output to the designated language.
So, when the button is pressed, it sends a get variable to the URL bar, which then sets the cookie. After I refresh the page, I get what I want.
Basically, I need to pass the GET variable and then refresh the page. How can I do this?
my php code:
<a href="?lang=zh_CN">ZH</a> <a href="?lang=en_US">EN</a>
Ok so here is what your page looks like:
> Read cookie and get the language > Read GET variable and SET COOKIE > Print out stuff in their language
You are simply doing things in the wrong order. If you do things in this order:
> Read GET variable and SET COOKIE > Read cookie and get the language > Print out stuff in their language
You'll already have the right language and have no need to refresh the page.