Re: Hacer LOGIN OUT

From: Date: Fri, 17 May 2002 17:41:12 +0000
Subject: Re: Hacer LOGIN OUT
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-22809@lists.php.net to get a copy of this message
Del manual de php un comentario de un participante, que puede servirte de ayuda http://php3.de/manual/en/features.http-auth.php Here is a code for the public sites enabling both logout bottom and timeout using php+mysql. Working for both browsers. The part "required" for each user protected page: <? function auth () { Header("WWW-Authenticate: Basic realm=\"ArmFN public site\""); Header("HTTP/1.0 401 Unauthorized"); echo "You have to authentificate yourself first \n"; exit; } mysql_connect("localhost","train","") or die("Unable to connect to SQL server"); mysql_select_db( "train") or die( "Unable to select database"); if(!isset($PHP_AUTH_USER)) { $timeout = mktime(date(G),date(i)+10,0,date("m"),date("d"),date("Y")); mysql_query("update users set login='$timeout' where id='$user' and pasw='$pass'") or die("k"); auth(); } else { $pass = $PHP_AUTH_PW; $user = $PHP_AUTH_USER; $nowtime = mktime(date(G),date(i),0,date("m"),date("d"),date("Y")); $quer2 = mysql_query("select * from users where id='$user' and pasw='$pass' and login > '$nowtime'") or die("kuk2"); if (mysql_num_rows($quer2) == "0") { $timeout = mktime(date(G),date(i)+10,0,date("m"),date("d"),date("Y")); mysql_query("update users set login='$timeout' where id='$user' and pasw='$pass'") or die("k"); auth(); } } ?> You can have a "logout" bottom with hidden $go="logout" form element and then have somewhere this part: if ($do == "logout") { mysql_connect("localhost","train","") or die("Unable to connect to SQL server"); mysql_select_db( "train") or die( "Unable to select database"); mysql_query("update users set login=0 where id='$PHP_AUTH_USER' and pasw='$PHP_AUTH_PW'") or die("k"); } Saludos José Valle desarrollo@comerciacom.com Responsable desarrollo B2B Comercia S.A.

« previous php.general.es (#22809) next »