Guys i'm unable to retrieve the session value. I've tried the entire day to fix the problem but failed. My situation is this:-
Im making a session class upon instantiation im starting the session auto via constructor.im getting two values "username" and "password" from login form then upon getting the values i'm assigning them to the session class attributes as follows
$username=$_POST['username'];
$password=$_POST['password'];
$session_object->session_username=$username;
$session_object->session_password=$password;
. Now as long as i echo $session_object->session_username; on the login form anywhere it shows the value. but when i try to display the value on any other page it shows nothing. I'm a beginner web developer but have read that sessions are stored on the server side and are accessible anywhere in the application.
I only have one object $session_object of the class Session,i'm not creating any more objects. Kindly help your help will be appreciated. using php 7.1, XAMPP server.
You can just use $_SESSION global array. But first of all you must call session_start().
session_start();
if ($_POST['username'] && $_POST['password']) {
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
} else {
$username = $_SESSION['username'];
$password = $_SESSION['password'];
}
echo "Username is '$username', password is '$password'.";