Hello again!
This time I’m working on a simple login system, where there’s only 1 user. The problem(s) I’m encountering is that when I’ve written the right username-password combination and clicked the login button the textfields go blank and I need to press login again(this time I don’t need to enter anything in the textfields).
[php]
<?php include 'Variables/variable-loginbuttons.php'; function prelogin(){ ?><form method = "POST" action = 'textfieldSwitchtest.php'>
<input title = "Username" name = "username" type = "text" /> <br>
<input title = "Password" name = "password" type = "password" /> <br>
<input value = 'Login' type = 'submit' name = 'login' /> <br>
</form>
<?php
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($username == "SuperAdmin123987" && $password == "IamTheBest543678"){
$loginbuttonsshowing=2;
$var_int = var_export($loginbuttonsshowing, true);
$var = "<?php\n\n\$loginbuttonsshowing = $var_int;\n\n?>";
file_put_contents('Variables\variable-loginbuttons.php', $var);
}else{
echo "Wrong username and password combination.";
}
}
}
function prelogout(){
echo “You are logged in as SuperAdmin123987.”;
?>
<?php
if(isset($_POST[‘logout’])){
echo “You have successfully logged out.”;
$loginbuttonsshowing=1;
$var_int = var_export($loginbuttonsshowing, true);
$var = “<?php\n\n\$loginbuttonsshowing = $var_int;\n\n?>”;
file_put_contents(‘Variables\variable-loginbuttons.php’, $var);
}
}
switch($loginbuttonsshowing){
case 1:
prelogin();
break;
case 2:
prelogout();
break;
default:
break;
}
?>
[/php]As you can see it is the switch that is causing the problem. It is loading either function and when the function is done I need to press one of the buttons to get the switch to react to the change of $loginbuttonsshowing.
How do you do make it require only one click to log in? And how do you make a button disappear?
I want to be able to log in with only 1 click of the log in button and I want to click the log out button once and then a new button that says ‘OK’ will replace it. After I’ve clicked the ‘OK’ button I’ll return to case 1, the login part.
Tia
/failstar