What is happening is that you are reloading the page, and by doing that the HTML snippet is reloaded as well. This in turn triggers another reload of the page, getting you into this infinite loop.
What is it exactly that you try to achieve?
If you just want to change the language of the user, just do the first two actions (the retrieve of the language and the change of the user and commit) and then show the page you want the user to go to (so not a reload page).
Hope this helps