I am trying to assign an array reference to the php $_SESSION variable, but cannot get it to work.
Consider a simple form:
<html>
<body>
<FORM action="post.php" method="post">
User name: <INPUT type="text" name="user"><br>
<INPUT type="submit" value="Submit">
</FORM>
</body>
</html>
where post.php is:
<?php
session_start();
if( !empty( $_POST ) ) {
$data=array();
$data['user']=$_POST['user'];
$data['pass']='xxxx';
$uid="1234";
$_SESSION[$uid] = &$data;
header( 'HTTP/1.1 303 See Other' );
header( 'Location: post.php?id='.$uid );
exit();
}
if( isset( $_GET[ 'id' ] )) {
$uid=$_GET[ 'id' ];
$user=$_SESSION[$uid]['user'];
} else {
exit();
}
?>
<html>
<body>
<?php
echo "<p>Username: ".$user."</p>";
?>
</body>
</html>
I get an empty username in the resulting post.php?id=1234 file.. What am I missing here?