0

Hi sorry I am just a baby in PHP. I want to get the value of $_SESSION['username'] but it gives me this error

Notice: Undefined offset: 0

Please see my code below. Your help will be greatly appreciated. Thanks.

<?php
session_start();

$_SESSION['username']='andrew';
$_SESSION['password']='pass';

$session=count($_SESSION);
echo "There are {$session} current sessions!";
echo "<br />";
echo $_SESSION[0]; //I want an output "andrew" but it fails.

?>
chris85
  • 23,846
  • 7
  • 34
  • 51

1 Answers1

0

Use

session_start();

$_SESSION['username']='andrew'; 
$_SESSION['password']='pass';

$session=count($_SESSION); 
echo "There are {$session} current sessions!"; echo "<br />";
echo $_SESSION['username']; //I want an output "andrew" but it fails.

?>
Jasmin Mistry
  • 1,459
  • 1
  • 18
  • 23