Jump to content

login/logout, again!


ochi

Recommended Posts

Hi everybody! I posted yesterday about login/logout, and I was sure it worked, but today I found a new mistake  :'(.

The problem is when I logout, I login again, but  I press "cancel" button, then as the previous USER and PASSWORD were correct, it allow me enter, but if I do it twice it works as I want. There is my code:

 

 

<?php

function check4login() {

	session_start();
    		if (isset($_SESSION['login'])) {
        		if (is_authorized($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])) {
            			$_SESSION['user'] = $_SERVER['PHP_AUTH_USER'];
            			unset($_SESSION['login']);
            			return true;
    			}    
    		} 

  		$_SESSION['login'] = true;
    		header("WWW-Authenticate: Basic realm=\"User and password\"");
    		header("HTTP/1.0 401 Unauthorized");
    	}

function is_authorized($usuario,$contrasena) {

	if ($usuario == 'user' && $contrasena == 'pass') {
		return true;
	} else {
		return false;
	}
}

check4login();
?> 

Link to comment
https://forums.phpfreaks.com/topic/189285-loginlogout-again/
Share on other sites

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.