0

I have a single HTML page that uses a carousel style log in system. Each step in the sign up works off of a different php script. There are 3 forms on the page that appear as the user progresses through the sign up. As they progress I need to keep their user id from the first step in a variable in order to update parts of their account later on.

The forms are executed via ajax and the first php script calls

session_start();

And then sets the session variable

$_SESSION['user_id']=$account_id;

As I progress through the form I put this at the top to check if the session variable was passing through

if (empty ($_SESSION['user_id'])) {
$message = 'Cant find the session id';}

And it is not. I don't have session_start() at the top of the other php scripts.

Am I misunderstanding how to pass this variable?

2
  • 1
    I don't have session_start() at the top of the other php scripts. You answered it yourself, if you don't have it initiated how do you expect it to work? By calling session_start() at the top of your script you're allowing it to read the session that has been previously saved from another step of your code. Commented Apr 20, 2014 at 5:06
  • 1
    You have to write session_start() in the next page also, so that it will work Commented Apr 20, 2014 at 5:06

1 Answer 1

1

session_start(); needs to be called at the beginning of each page load in order to make $_SESSION available.

Don't worry, it won't reset the session. In the simplest terms, session_start() just tells PHP that you are expecting a session to exist, and it needs to run its code to give you access to it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the clarification on session_start() not resetting the session

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.