Sessions, that's your answer. We are using sessions to bypass some automatic functions.
Your PHP script detecting the mobile browser, even if you are clicking on a different link, it will go to it, but will detect again the browser and jump back.
Session will solve the problem. When the...