If you're specifically talking about sending a location header to redirect the user, I just don't understand the technical need for that. I don't see any problem which gets resolved by redirecting the user to another page, I don't understand why you think that's a solution to any problem you think you have. They're already on your site, PHP can do anything you want it to do, I don't understand why you've come to the conclusion that the thing you want PHP to do is to just redirect the user and start PHP over again. It's already running, just do what you need it to do the first time. It almost seems like you've learned a few things about PHP, you have a solution, and now you're searching for a problem for your solution. I just don't see the need to redirect, I don't see any problem that a redirection solves. The only time you need to redirect someone is if you want them on a different page for whatever reason, maybe because they've just submitted a form, you processed the form, and you don't want them to hit refresh and re-submit the form. Or they just logged in, and you're taking them to wherever they go after logging in. Those are the cases when you might redirect someone. You're describing your solution to redirect a user and I'm missing the problem you're trying to solve by doing that.
Why? Why do you need to know that? If you're just interested in tracking traffic and things like that, I would suggest something like Google Analytics. Otherwise, why would any page care where the user came from, why is that relevant to what the page is supposed to produce?
I'm not sure if we're experiencing a language or terminology barrier or what, but I'm having a hard time understanding why you think you have all of these requirements. A web page, or PHP page, or whatever, typically has a single purpose in terms of what it displays, and that purpose typically does not depend on where the user came from. A certain URL, in general, should always show the same content regardless of how the user got there. You wouldn't want people to share a certain URL and have it show different content for different people, that wouldn't make sense to them. You're talking about setting session variables when the user gets to the page, why? The session is for tracking who the user is, if they just got to your site you don't know anything about them, why do you think you have to use the session? It sounds like you're learning individual tools in PHP and then trying to apply everything to your site even though it's not necessary. Not every page or site needs to use every PHP function.