xcoderx Posted November 14, 2008 Share Posted November 14, 2008 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 More sharing options...
xcoderx Posted November 14, 2008 Author Share Posted November 14, 2008 anything like this? session_start(); unset($_SESSION['MyLoginPage']); session_destroy(); header('Location: login.php'); exit; } im not sure ??? Link to comment https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/#findComment-689968 Share on other sites More sharing options...
zenag Posted November 14, 2008 Share Posted November 14, 2008 //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; } } Link to comment https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/#findComment-689969 Share on other sites More sharing options...
xcoderx Posted November 14, 2008 Author Share Posted November 14, 2008 ok im giving it a try 1 min Link to comment https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/#findComment-689971 Share on other sites More sharing options...
xcoderx Posted November 14, 2008 Author Share Posted November 14, 2008 thanks alot ganesh bro it helped Link to comment https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/#findComment-689973 Share on other sites More sharing options...
xcoderx Posted November 14, 2008 Author Share Posted November 14, 2008 got one question supposing i want to display error message within the login form how would i do that? Link to comment https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/#findComment-689979 Share on other sites More sharing options...
zenag Posted November 14, 2008 Share Posted November 14, 2008 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> Link to comment https://forums.phpfreaks.com/topic/132667-solved-help-with-logout-here/#findComment-689985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.