0

Why my session variable is not passing between these 2 pages?

<?php
session_start();
$_SESSION["test"]= "12345";
echo "<a href='8.php'>move to another page</a>";
?>

second webpage 2.php

<?php
echo $_SESSION["test"];
?>

The session variable is empy in the second page

1
  • 9
    You should also use session_start() in second page Commented Oct 23, 2018 at 10:40

2 Answers 2

1

you need to set session_start() on every page on which you want to see $_SESSION array. It is nice to have one file in which you will set session_start() and include it on every page on which you want to use sessions.

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

Comments

0

Why my session variable is not passing between these 2 pages?

Add the session_start() to your webpage2.php

<?php
session_start();
echo $_SESSION["test"];
?>

Read more info about session here

Comments

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.