So I have a form that allows the user to select a city. Once selected, this city is then saved to a $_SESSION variable as such : $_SESSION['city_selected'] = $_POST['location_select'];

This works fine once selected. When I var_dump($_SESSION); I see my variable perfectly on after selecting the city and the page refreshing.

Then, if I move to a different page or refresh the same page - the var_dump(); returns NULL

I can't seem to figure this out. My PHP session ID doesn't change.

I am using WAMP on a local server, and session files are saving in the \tmp folder.

Am I missing something? What the heck is happening?

  • Make sure that you have session_start(); at the top of all your scripts. Oct 11, 2021 at 1:17
  • PHP sessions don't work on a lot of hosts and are incompatible with many features such as CDNs and page caching plugins because of how they work. PHP sessions also rely on a session id cookie so they can't be sued to bypass cookie regulations/laws/banners
    – Tom J Nowell
    Oct 11, 2021 at 9:24

1 Answer 1


Are you using session__start() ; at the top of that other page? You always need to retrieve session data when changing pages.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.