Ops. I am sorry it is not really clear, but you cannot use global variables in this way in Web code. The sequence you expected to come from one browser can be interrupted by other client's browser at any time.
Use cookie or session variable (which is cookie based as well).