Vote count:
0
I started studying PHP few weeks ago and I'm a little bit confused with conditional embed HTML between PHP code blocks and setting cookies. What I want to do is a simple code that checks your name, password and e-mail, sets cookie (if they are valid); when you have already logged in, you should see "log out" button. So, my code:
<?php
if (($_POST['name'] == 'admin') and ($_POST['pass'] == 'admin') and ($_POST['mail'] == 'admin@gmail.com')) {
setcookie("Test","Value");
echo "Success!!! <br/>";
}
if ($_POST['logout']) {
setcookie("Test", "", time() - 3600);
echo "Goodbye!";
}
?>
<?php if(isset($_COOKIE['Test'])) :
?>
<input type="submit" value="logout"/><br/>
<?php endif ?>
<?php if(!isset($_COOKIE['Test'])) :
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<form action="" method="POST">
<input type="text" name="name"/><br/>
<input type="text" name="pass"/><br/>
<input type="text" name="mail"/><br/>
<input type="submit" value="go"/><br/>
<?php endif ?>
However, I can't figure out how to make it work properly: when I enter correct username, password and mail, I don't see "logout" button, there's still a form and i need to enter username again to finally see "logout". Second problem, when I press "logout", nothing happens. I guess I can't set the cookie because headers were already sent, but I can't figure out how to rewrite it.
asked 1 min ago
Conditional emebed html between PHP code blocks + setting cookies
Aucun commentaire:
Enregistrer un commentaire