zuko Posted November 17, 2008 Share Posted November 17, 2008 i have this login script. i can use it for login, but i can't use it for logout. can anyone tell me what's the problem. here is my login script. <? include "header.php"; switch ($mod){ case "logout" : /*session_unregister($_SESSION[usrnm]); $_SESSION[usrnm] = ""; unset($_SESSION[usrnm]); session_unregister($_SESSION[id]); $_SESSION[id] = ""; unset($_SESSION[id]);*/ setcookie("username",""); setcookie("id",""); message_url("Anda telah logout..Terima kasih atas kunjungannya!!!","/"); break; default : if (emptyString($_POST[usrnm])) message_back('Username belum diisi'); if (emptyString($_POST[psw])) message_back('Password belum diisi'); //cek di table (proses authentifikasi) $pass_md5 = md5($_POST[psw]); $qr = mysql_query("SELECT * FROM stream WHERE username='$_POST[usrnm]' AND password='$pass_md5'"); $loaduser = mysql_fetch_assoc($qr); if (mysql_num_rows($qr) == '1'){ /*Create session session_register("usrnm"); $_SESSION[usrnm]="$loaduser[username]"; session_register("id"); $_SESSION[id]="$loaduser[id]";*/ setcookie("username","$loaduser[username]"); setcookie("id","$loaduser[id]"); message_url("Selamat Datang $loaduser[nama]","/admin.php"); } else { message_back('Username/Password Anda salah... data tidak ditemukan'); } break; } include "footer.php"; ?> Link to comment https://forums.phpfreaks.com/topic/133038-cannot-logout/ Share on other sites More sharing options...
DarkerAngel Posted November 17, 2008 Share Posted November 17, 2008 is there something wrong with session_destroy(); ??? also for the cookies, set a expire past the current time: setcookie("username","", time()-3600); Link to comment https://forums.phpfreaks.com/topic/133038-cannot-logout/#findComment-691917 Share on other sites More sharing options...
zuko Posted November 17, 2008 Author Share Posted November 17, 2008 ehh... session_destroy();??? i dont understand Link to comment https://forums.phpfreaks.com/topic/133038-cannot-logout/#findComment-692094 Share on other sites More sharing options...
revraz Posted November 17, 2008 Share Posted November 17, 2008 To end a session just do session_start(); session_destroy(); Link to comment https://forums.phpfreaks.com/topic/133038-cannot-logout/#findComment-692221 Share on other sites More sharing options...
zuko Posted November 18, 2008 Author Share Posted November 18, 2008 where i should put that? in which line? Link to comment https://forums.phpfreaks.com/topic/133038-cannot-logout/#findComment-692533 Share on other sites More sharing options...
waynew Posted November 18, 2008 Share Posted November 18, 2008 On your logout page. Just create a page called logout.php and write the following in it: session_start(); session_destroy(); header('Location: login.php'); //change this to suit your needs Link to comment https://forums.phpfreaks.com/topic/133038-cannot-logout/#findComment-692583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.