php - Trouble with session variables

19

I'm trying to set a session variable and use it on another page.

I have: pg1

session_start();
$_session['sessionID'] = $row['ID'];

Then on page two I have.

session_start();
$userID = $sessionID;

But when I use JC to alert this out I get nothing. Am I doing this wrong?

505

Answer

Solution:

Rather than:

$userID = $sessionID;

Use:

$userID = $_SESSION['sessionID']

You need to specify the$_SESSION there because that is the array you stored the value in :)

Have a look at this session tutorial if you want.

31

Answer

Solution:

On the second page, you'll need to say

$userID = $_SESSION['sessionID'];
801

Answer

Solution:

You need to do the following on page 2:

session_start();
$userID = $_SESSION['sessionID'];

You also need to use $_SESSION, not $_session

People are also looking for solutions to the problem: PHP how to use range() for float numbers

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.