I have this page I am working on which is a sort of a game. From page to page I am passing the user name like this
index:
<form method="GET" action="start.php">
<label> Name: </label>
<input type="text" name="username"><br>
<input type="submit">
</form>
Where I retrieve the name on the second page like this:
<?php
session_start();
$_SESSION['username'] = $_GET['username'];
?>
-
<?php
session_start();
if(isset($_SESSION['username'])){
echo "Welcome: " . $_SESSION['username'];
}
else{
echo "Name is unknown";
}
?>
And also on the third:
<p>
<?php
session_start();
echo $_SESSION['username']
?>
</p>
And this code is working just fine. Now I was making an if
statement which, when ever you don't enter a name, you won't continue to the next page. I added this code to the first page and this is working for the first page.
<?php
session_start();
$_SESSION['username'] = $_GET['username'];
if($_SESSION['username'] != "")
{
header("Location: start.php");
}
?>
So after adding this, you won't go further unless you do enter a name. But by doing this for a reason I don't know yet and couldn't find, the $_SESSION['username'] = $_GET['username'];
isn't working and the names are not passed through
This is the link if you like to play: http://i333180.iris.fhict.nl/site (not finished yet)
` counts as output, therefore `session_start()` will fail with [headers already sent](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php)
– Marc B Jul 07 '15 at 14:22