So I create a session on one page and create a new variable called uName and assign a value.
I go to another page and try to echo the value but I get an error:”Undefined variable _SESSION”
here is the code:
The page where I start the session and create the variable uName
<?php
session_start();
$_SESSION['uName'] = "Mike";
?>
The page where I try to echo the variable’s value:
<?php echo "My Name is " . $_SESSION['uName'];?>
There is nothing else in my code except for a shell of a page just html, head, title, body and paragraph tags, all properly nested.
You need to call session_start() again at beginning of the new file, like so: