When trying to print/echo a specific part of my session array it wont return anything besides a '1'
it also gives an error telling me that user_name
is an undefined index but when I var_dump
my session it shows it exists.
What is the correct way to only show the user_name
part of my session on screen?
I've tried print_r
, echo
, print
but none of these seem to work
session_start();
include '../php/database.php';
var_dump($_SESSION['userdata']);
echo "Welcome back " . print_r($_SESSION['userdata']['user_name'][0]) . "!";
I expect the output to be "Welcome back user_name" which in this case should be the text string "empty"
var_dump:
array(1) { [0]=> array(1) { [0]=> array(8) { ["user_id"]=> string(1) "1" [0]=> string(1) "1" ["user_name"]=> string(5) "empty" [1]=> string(5) "empty" ["user_pass"]=> string(5) "empty" [2]=> string(5) "empty" ["user_email"]=> string(17) "empty@hotmail.com" [3]=> string(17) "empty@hotmail.com" } } }
output
Notice: Undefined index: user_name in C:\xampp\htdocs\Projecten\loginSystem\pages\dashboard.php on line 7 Welcome back 1!