No clue what you are having trouble with, but seems like you have a form that submits to a PHP page, and want the username to display on that page, and be displayed on all pages afterwards.
Sample Form:
<form name="submitName" action="saveName.php" method="POST">
Name: <input type="text" name="usersName" /><br>
<input type="submit" value="Continue" />
</form>
PHP to Process Form (saveName.php
)
<?php
session_start(); // Starts the session so you can save the name
$name = $_POST['usersName']; // Get the name submitted
$_SESSION['name'] = $name; // Save the name in a session
echo strip_tags($name); // Output the user's name to the HTML page, after removing PHP and HTML tags from string
?>
On later pages, $_SESSION['name']
contains the user's name.
<?php
session_start();
if(isset($_SESSION['name'])) {
echo $_SESSION['name'];
}
else {
echo <<<USERFORM
<form name="submitName" action="saveName.php" method="POST">
Please enter your name: <input type="text" name="usersName" /><br>
<input type="submit" value="Continue" />
</form>
USERFORM;
}
?>
If you redefine your question, we can help more.