Issue passing PHP session variables

Viewed 56

I am trying to pass PHP session variables from page to page. I am receiving an undefined index error. I am using PHP 8.12 on apache 2.48 on localhost.

I have tried with a couple of very simple code snippets, and I am getting the same error, for example:

page1.php:

<?php
    session_start();
    $_SESSION["name"]="xxx";
    header ("location:page2.php");
    exit;
?>

If I echo $_SESSION["name"] on page1.php, the correct value is displayed.

page2.php:

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

On page 2 I am receiving an undefined index "name" error.

I have a feeling there maybe something I am missing in the php.ini file as I can't see any reason why such simple code should be failing.

0 Answers
Related