codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

Refreshing logout the user from the page


By : , Category : php

Use

if(!isset($_GET['logout']))
{
    if(!isset($_SERVER['HTTP_REFERER']))
    {
        header("location: auth.php");
        exit;
    }
    else
    {
    $page = $_SERVER['PHP_SELF'];
    $sec = 10;
    header("Refresh: $sec; url=$page");
    }
} 
else
{
    print "/*Error in refreshing*/";
}

Hope this will help!

ReLated :

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
<?php 
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {

$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.setHeader("Pragma","no-cache"); 
httpResponse.setDateHeader ("Expires", 0); 
if (session.getAttribute("uid") == null || session.getAttribute("username") == null ) {                               
                 response.sendRedirect("/invalidSession.jsp");
                 return;
 }

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 http://127.0.0.1, it works great and is able to access the user object as intended.

For anyone working with something similar, be sure to continually use http://127.0.0.1 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.

Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .