tomaac Posted December 12, 2005 Report Share Posted December 12, 2005 Man ir sekojošs autentifikācijas skriptiņš: <? header("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: post-check=0, pre-check=0",false); header("Pragma: no-cache"); session_cache_limiter("public, no-store"); session_start(); function auth_user() { $realm = mt_rand( 1, 1000000000 ); header('WWW-Authenticate: Basic realm="Protected:[iD'.$realm.']"'); header('HTTP/1.0 401 Unauthorized'); die("Unauthorized access forbidden!"); } if(isset($_GET['logout'])) { auth_user(); } if (!isset($_SERVER['PHP_AUTH_USER'])) { auth_user(); } else if (!isset($_SERVER['PHP_AUTH_PW'])) { auth_user(); } //paroles iegusha no sql un apstrade if ok { main_code; echo "You are now logged in <br />"; echo "<a href=\"".$_SERVER['PHP_SELF']."?logout=y\">Logout</a>"; ?> viss it kā strādā, bet problēma ir tāda, ka tad kad nospiež linku logout - atkal parādās autentifikācijas forma, bet fonā paliek nenodzēsta informācija (viss kas tika darīts), gribētos, lai pēc logout fons būtu tukšs. Link to comment Share on other sites More sharing options...
Klez Posted December 12, 2005 Report Share Posted December 12, 2005 tas kas izlogo, skripta dalja, pieliec rindinju: session_destroy(); Link to comment Share on other sites More sharing options...
v3rb0 Posted December 12, 2005 Report Share Posted December 12, 2005 un php manulā pie session_destroy() useru komentāros var palasīties par varmācīgākām metodēm, ja session_destroy() īsti nestrādā. Link to comment Share on other sites More sharing options...
blackhalt Posted December 13, 2005 Report Share Posted December 13, 2005 (edited) Cancel laikam tāpat jāspiež. logout.php: <?php header('WWW-Authenticate: Basic realm="Autorizacija"'); header('HTTP/1.1 401 Unauthorized'); echo"<script type=\"text/javascript\">window.location='./index.php';</script>"; echo'<noscript><a href="./index.php">Tur</a> <meta http-equiv="refresh" content="0; url=./index.php"></noscript>'; die(); ?> Edited December 13, 2005 by blackhalt Link to comment Share on other sites More sharing options...
Recommended Posts