0

I have two buttons, one to log in and another to log out. Now I want only one button, I want that it only shows the log in button. And if you are logged in, then the page refresh (already done) but then I want that the log in button is changed into a logoff button. So that you don't log in two or more times a day and you have to log out first.

<form action="begintijd.php" method="POST">
    <input name="begintijd" value="aanmelden" type="submit">
</form>
<form action="eindtijd.php" method="POST">
    <input name="eindtijd" value="afmelden" type="submit">
</form>

header("Refresh: 2; index.php");

So you can log in and off so many times you want. But I only want that you can log in once and then you first have to log out before you can log in.

(some things are in dutch, you can overwrite it if you want)

icedwater
  • 4,701
  • 3
  • 35
  • 50

5 Answers5

1

Simple.

You are using a cookie to set login data. If cookie is set, then display button 1, else display button 2, like;

<?php
if (isset($_COOKIE["user"])){
  echo '<form action="begintijd.php" method="POST">
    <input name="begintijd" value="aanmelden" type="submit">
</form>';
}else{
  echo '<form action="eindtijd.php" method="POST">
    <input name="eindtijd" value="afmelden" type="submit">
</form>';
}
?>
Alfred
  • 21,058
  • 61
  • 167
  • 249
0

Use sessions: Using sessions & session variables in a PHP Login Script

<?PHP

session_start();

if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {

echo '<form action="begintijd.php" method="POST">'.
    '<input name="begintijd" value="log in" type="submit">'.
'</form>';

}
else
{
 echo '<form action="begintijd.php" method="POST">'.
    '<input name="begintijd" value="log out" type="submit">'.
'</form>';
}

?>
Community
  • 1
  • 1
0

You need to read about session variables or cookies.

SamYan
  • 1,553
  • 1
  • 19
  • 38
0

If your are using sessions.You can do using this.

<?php if($_SESSION['logged_in']==true){?> //if user is logged in show logout button
<form action="begintijd.php" method="POST">
<input name="begintijd" value="aanmelden" type="submit">
</form><?php } else {?>//if user is logged out show login button
<form action="eindtijd.php" method="POST">
<input name="eindtijd" value="afmelden" type="submit">
</form><?php }?>
0

You can try this.

<form action="<?=($_SESSION['login']!="")?"begintijd.php":"eindtijd.php"?>" method="POST">

    <input name="<?=($_SESSION['login']!="")?"begintijd":"eindtijd"?>" value="<?=($_SESSION['login']!="")?"aanmelden":"afmelden"?>" type="submit">

</form>

Send us your begintijd.php and eindtijd.php codes

A. Zalonis
  • 1,599
  • 6
  • 26
  • 41