it seems to be simple but anyhow i can't pass my sessionvariable from the first page to the second page. I have searched for solutions but can't find any. As far as i know i am starting the session on bothe pages before sending any headers.
code on page1
<?php session_start()?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="page2.php" method="POST">
<input type="text" name="username" id="username">
<input type="submit" name="submit" id="submit">
<?php if(isset($_POST['submit'])) {
$username = $_POST['username'];
$_SESSION['username'] = $username;
}
?>
</form>
</body>
</html>
Code on page 2
<?php session_start()?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
echo "This is from my session: "." ". $_SESSION['username'];
?>
</body>
</html>
So on the second page (page2.php) i get this error:
Notice: Undefined variable: username in C:\xampp\htdocs\page2.php on line 12
This is from my session: