Why session variables is not passing from first page to second page? I"m using XAMPP

 Let I solve your problem.

Earlier I do also faced this problem. Before I give you the solution , let me give you important details about the session. It's about session id and it's storage.

When a php session is started at first, there created a 32 digit hexadecimal value as an identifier we say session id. (Session id will be destroyed when the user closes the browser or after certain time that the Programmer set. ) After creating a 32 digit hexadecimal id , the server sends a cookie with PHPSESSID to the user's system. PHPSESSID stores the session id. (Now session id is available at both sides i.e client side and server side). When you browse in the particular website, the stored PHPSESSID is sent along with the request(mean you are accessing another page). So that you can access session variables in another page too. 

Now coming to point,

When we are using XAMPP, both the server and the client are in the same system. 

session1.php

session2.php
I opened session2.php at first it is showed an undefined array in the code.  Actually we are using the XAMPP at present. All the web pages are located at one server.  We have note here one thing we are not opening a website we are just opening a php file in our system. When I opened session2.php it showed an error.


At first we need to open the session1.php in order save cookie with PHPSESSID (random 32 digit hexadecimal session id). After then we can access any session variable from any php file in that particular folder. Better to turn on the Internet connection which helps in storing the cookie in your system( in the browser storage). 

session1.php 

session2.php

When we close the browser the cookie containing PHPSESSID will be destroyed as we did not mention the expiry time. And when we open the session2.php - it shows an error again.

Thank you !

Post a Comment

0 Comments