Refreshing logout the user from the page


        header("location: auth.php");
    $page = $_SERVER['PHP_SELF'];
    $sec = 10;
    header("Refresh: $sec; url=$page");
    print "/*Error in refreshing*/";

Hope this will help!

You don't have to use jQuery to do the thing. Just make sure that PHP script is executed before you output your HTML:

// check login here

$username = trim(htmlentities(mysql_real_escape_string($_POST['username'])));
$password = trim(htmlentities(mysql_real_escape_string($_POST['password'])));
if (!empty($username) && !empty($password)) {
    $_SESSION['username'] = $username;
    $message = "<br/> welcome ", $username;
 } else {
    $message = "Please enter correct username or password";
} else {
    $message = "please Login";
// here is the menu
// here you can echo any messages that comes from login attempt
if (isset($message)) {
    echo $message;
// and the login form

Just be sure that whole PHP actions are made before rendering the view.

Added the following code on top of each pages which needs login:

HttpServletResponse httpResponse = (HttpServletResponse)response;

httpResponse.setHeader("Cache-Control","no-cache, no-store, must-revalidate"); 
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
httpResponse.setDateHeader ("Expires", 0); 
if (session.getAttribute("uid") == null || session.getAttribute("username") == null ) {                               

How you unset the cookie??

If you use unset($_COOKIE['loggedout']);

then replace this with setcookie('loggedout');

That is for set cookie use: setcookie('loggedout',1);

for unset cookie use: setcookie('loggedout');

This worked for me.. any doubt please ask me..

So it appears that my code is actually doing what is intended. I couldn't figure out why it would sometimes work.

The solution (well, problem) was that I was accessing the site via localhost. Apparently this does not guarantee the same IP address at all times. Instead, if I access the site via, it works great and is able to access the user object as intended.

For anyone working with something similar, be sure to continually use and not localhost to remain consistent. I think this has caused me problems in the past as well but I was not aware of at the time.


Message :
Login to Add Your Comments .
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © All Rights Reserved .