Waiting Answer December 23, 2024

Unable To Send Session Variable From One Php Page To Another

I have set a session on a page, but it does not work when it calls on another page. I have tried all possible fixes, but they don't work. I don't know where I am going wrong.

Here is my sample code.


page1.php:

     <?PHP
         $_SESSION['msg'] = "This is a test message";
    ?>

But when it calls on another page, this is not working

    <?PHP
         echo $_SESSION['msg'];
    ?>

Can someone help me to fix this?

Answers
2024-12-23 14:27:19

The inbuilt PHP function session_start() needs to be defined at the top of the page. A session is started with session_start() at the top.