Jump to content

[SOLVED] help with logout here


xcoderx

Recommended Posts

hi friends im unable to set a logout here, how can i delete the cookies?

 

<?php
$username = "user";
$password = "pass";
$randomword = "bibblebobblechocolatemousse";

if (isset($_COOKIE['MyLoginPage'])) {
   if ($_COOKIE['MyLoginPage'] == md5($password.$randomword)) {
?>

<?php
      exit;
   } else {
      echo "<p>Bad cookie. Clear please clear them out and try to login again.</p>";
      exit;
   }
}

if (isset($_GET['p']) && $_GET['p'] == "login") {
   if ($_POST['name'] != $username) {
      echo "<p>Sorry, that username does not match. Use your browser back button to go back and try again.</p>";
      exit;
   } else if ($_POST['pass'] != $password) {
      echo "<p>Sorry, that password does not match. Use your browser back button to go back and try again.</p>";
      exit;
   } else if ($_POST['name'] == $username && $_POST['pass'] == $password) {
      setcookie('MyLoginPage', md5($_POST['pass'].$randomword));
      header("Location: $_SERVER[php_SELF]");
   } else {
      echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>";
   }
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?p=login" method="post"><fieldset>
<label><input type="text" name="name" id="name" /> Name</label><br />
<label><input type="password" name="pass" id="pass" /> Password</label><br />
<input type="submit" id="submit" value="Login" />
</fieldset></form>

Link to comment
https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/
Share on other sites

//just set time in setcookie to delete cookie...

$username = "user";
$password = "pass";
$randomword = "bibblebobblechocolatemousse";

if($_GET["logout"]=="yes")
{
setcookie("MyLoginPage","",time()-3600);
header("Location: $_SERVER[php_SELF]");
}
if (isset($_COOKIE['MyLoginPage'])) {
   if ($_COOKIE['MyLoginPage'] == md5($password.$randomword)) { echo "<a href='?logout=yes'>logout</a>";
?>

<?php
      exit;
   } else {
      echo "<p>Bad cookie. Clear please clear them out and try to login again.</p>";
      exit;
   }
}


its a sample code ...try this out..
<?php

$username = "user";
$password = "pass";
$randomword = "bibblebobblechocolatemousse";

if($_GET["logout"]=="yes")
{
setcookie("MyLoginPage","",time()-3600);
header("Location: $_SERVER[php_SELF]");
}
if (isset($_COOKIE['MyLoginPage'])) {
   if ($_COOKIE['MyLoginPage'] == md5($password.$randomword)) { echo "<a href='?logout=yes'>logout</a>";
?>

<?php
      exit;
   } else {
      echo "<p>Bad cookie. Clear please clear them out and try to login again.</p>";
      exit;
   }
}

if (isset($_POST['p']) && $_POST['p'] == "login") {

$name = trim($_POST['name']);
        if (empty($name)) {
          $error['name'] = '*';
	  }

  if ($_POST['name'] == $username && $_POST['pass'] == $password && !$error) {
      setcookie('MyLoginPage', md5($_POST['pass'].$randomword));
      header("Location: $_SERVER[php_SELF]");
   }
   else
   {
   echo "* fields are required";
   }
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><fieldset>
<label><input type="text" name="name" id="name" /> Name</label><label><? echo $error['name'] ?></label><br />
<label><input type="password" name="pass" id="pass" /> Password</label><br />
<input type="hidden" name="p" value="login" />
<input type="submit" id="submit" value="Login" />
</fieldset></form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.