Explore Topics

Unable To Send Session Variable From One Php Page To Another

Last Updated : 18 Apr, 2025 - Asked By Ashok

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?

php  session 

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.

Your Answer



Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certification

Earn certifications to enhance your resume.

Q&A Image
Q&A

Hands-on projects to improve your skills.