Copy link to clipboard
Copied
I am trying to access the session variable $_SESSION['MM_Username'] in one of my php pages, but it is somehow showing empty (i.e it does not contain the username that was entered during login).
I checked and confirmed that my login.php function is properly setting the MM_Username session variable by echoing it from the login function.
So why can't I read it from another php file in the same session? Do I need to do something else before the session variables can
be properly read from any php file in the same session? Any help would be appreciated.
Copy link to clipboard
Copied
You need to start a session on the other page to show the session variable.
Put this code on the first line of your page:
<?php
session_start(); // start up your PHP session!
?>
Copy link to clipboard
Copied
Thanks for the suggestion. I tried it but I still can't get the username session variable. Is there anything else that need to be done?
Copy link to clipboard
Copied
Here is a test code I am using to access the session variable $_SESSION['MM_username'] from the php page test.php. But it is not working.
I get an empty string all the time for $username. Can any one see something wrong with this code?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php require_once('Connections/MyTestingConn.php'); ?>
<?php session_start(); ?>
<?php
$username = "-1";
if (isset($_SESSION['MM_username'])) {
$username = $_SESSION['MM_username'];
echo $username;
}
else
echo "Eror: can not access session variable";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
</body>
</html>
------------------------------------------------------------------------------------------------------------
Copy link to clipboard
Copied
I found what the problem was. This question can be considered as answered.
Copy link to clipboard
Copied
Answered.
Copy link to clipboard
Copied
So what was the problem then I'm curious.
Copy link to clipboard
Copied
I found out in Dreamweaver documentation that I had to bind the MM_Username session variable from with the login page. A very simple procedure I was not aware I had to do. But most probably, I also needed what you had suggested. So, it looks that I was missing two things.
But everything is OK now. Thanks again for the help!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more