I have a Well, there is a lot of code missing. Where is your login script? First, you need a For example: Your login.php In your index.html you can do: I think your PHP should look something like that: Use either brackets in both if and else or use none. By the way you don't need an elseif if you're only checking a boolean. (there are only 2 possibilities)
<form> with the input fields (login and password) and a submit button.<form action='login.php' method='post'>
<input type='text' name='loginname'></input>
<input type='password' name='loginpassword'></input>
<input type='submit'>Submit</input>
</form>
<?php
session_start();
// Dont forget to check your variables
$loginname = $_POST["loginname"];
$password = $_POST["loginpassword"];
// Check the correct login (for example with a database)
if ($login_correct) {
$_SESSION["username"] = $loginname;
$_SESSION["logged"] = true;
header("index.html");
exit;
else {
$_SESSION["logged"] = false;
header("registerform.html");
exit;
}
}
?>
<?php
session_start();
if($_SESSION['logged'] == true){
echo $_SESSION["username"];
echo '<a href="logout.php"><span>Logout</span></a></li>';
}
else {
echo '<a href="registerform.html"><span>Login/Register</span></a></li>';
}
?>
<?php
session_start();
username = $_SESSION["username"]
if($_SESSION['logged'] == true) {
echo '<a href="logout.php"><span>' . username. 'Logout</span></a></li>';
}
else {
echo '<a href="registerform.html"><span>Login/Register</span></a></li>';
}
?>