Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > logout Auto ทำยังไงเราจะให้ logout อัตโนมัติเวลาเราปิดหน้าเว็ปครับ เพราะถ้าไม่ loguot เวลา login เข้า



 

logout Auto ทำยังไงเราจะให้ logout อัตโนมัติเวลาเราปิดหน้าเว็ปครับ เพราะถ้าไม่ loguot เวลา login เข้า

 



Topic : 013290

Guest




ทำยังไงเราจะให้ logout อัตโนมัติเวลาเราปิดหน้าเว็ปครับ เพราะถ้าไม่ loguot เวลา login เข้ามาอีกทีมันจะไม่มันมันจะผ่านหน้า login ไปเลยครับ
ขอบคุณครับ


Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 21 เม.ย. 2550 13:26:06 By : sorajng View : 5991 Reply : 4
 

 

No. 1

Guest


ลองใช้ session ซิครับ แล้วเก็บค่าไว้ตลอดจนกว่าจะปิดหน้า web หรือ logout






Date : 21 เม.ย. 2550 14:38:14 By : tigger.php
 


 

No. 2

Guest


ผมใช้ cookie ครับ แต่เราไม่ต้องกำหนดเวลาของ cookie เพราะเมื่อเราปิด browser ตัว cookie จะถูกทำลายอัตโนมัติครับ ..............ได้ไม่ได้ยังงัยก็บอกกันบ้างนะครับ
Date : 21 เม.ย. 2550 14:56:33 By : martman
 

 

No. 3

Guest


คือว่าผมมันมือใหม่ครับ ตาม code นี้แก้ตรงไหนครับ


รบกวนผู้รู้หน่อยครับ
ขอบคุณครับ




<?// ----------------------------------------------------------------------
// Original Author of file: Jim McDonald
// Purpose of file: Session handling
// ----------------------------------------------------------------------

/**
* Set up session handling
*
* Set all PHP options for PostNuke session handling
*/
function pnSessionSetup()
{
global $HTTP_SERVER_VARS;

$path = pnGetBaseURI();
if (empty($path)) {
$path = '/';
}
$host = $HTTP_SERVER_VARS['HTTP_HOST'];
if (empty($host)) {
$host = getenv('HTTP_HOST');
}
$host = preg_replace('/:.*/', '', $host);

// PHP configuration variables

// Stop adding SID to URLs
ini_set('session.use_trans_sid', 0);

// User-defined save handler
ini_set('session.save_handler', 'user');

// How to store data
ini_set('session.serialize_handler', 'php');

// Use cookie to store the session ID
ini_set('session.use_cookies', 1);

// Name of our cookie
ini_set('session.name', 'TempSID');

// Lifetime of our cookie
$seclevel = pnConfigGetVar('seclevel');
switch ($seclevel) {
case 'High':
// Session lasts duration of browser
$lifetime = 0;
// Referer check
//ini_set('session.referer_check', "$host$path");
ini_set('session.referer_check', "$host");
break;
case 'Medium':
// Session lasts set number of days
$lifetime = pnConfigGetVar('secmeddays') * 86400;
break;
case 'Low':
// Session lasts unlimited number of days (well, lots, anyway)
// (Currently set to 25 years)
$lifetime = 788940000;
break;
}
ini_set('session.cookie_lifetime', $lifetime);

if (pnConfigGetVar('intranet') == false) {
// Cookie path
ini_set('session.cookie_path', $path);

// Cookie domain
// only needed for multi-server multisites - adapt as needed
//$domain = preg_replace('/^[^.]+/','',$host);
//ini_set('session.cookie_domain', $domain);
}

// Garbage collection
ini_set('session.gc_probability', 1);

// Inactivity timeout for user sessions
ini_set('session.gc_maxlifetime', pnConfigGetVar('secinactivemins') * 60);

// Auto-start session
ini_set('session.auto_start', 1);

// Session handlers
session_set_save_handler("pnSessionOpen",
"pnSessionClose",
"pnSessionRead",
"pnSessionWrite",
"pnSessionDestroy",
"pnSessionGC");
return true;
}

/*
* Session variables here are a bit 'different'. Because they sit in the
* global namespace we use a couple of helper functions to give them their
* own prefix, and also to force users to set new values for them if they
* require. This avoids blatant or accidental over-writing of session
* variables.
*
*/

/**
* Get a session variable
*
* @param name name of the session variable to get
*/
function pnSessionGetVar($name)
{
global $HTTP_SESSION_VARS;

$var = "PNSV$name";

global $$var;
if (!empty($HTTP_SESSION_VARS[$var])) {
return $HTTP_SESSION_VARS[$var];
}

return;
}

/**
* Set a session variable
* @param name name of the session variable to set
* @param value value to set the named session variable
*/
function pnSessionSetVar($name, $value)
{
global $HTTP_SESSION_VARS;
$var = "PNSV$name";

global $$var;
$$var = $value;
$HTTP_SESSION_VARS[$var] = $value;
session_register($var);

return true;
}

/**
* Delete a session variable
* @param name name of the session variable to delete
*/
function pnSessionDelVar($name)
{
$var = "PNSV$name";

global $$var;
// Fix for PHP >4.0.6 By John Barnett (johnpb)
//unset($$var);
unset($GLOBALS[$var]);

session_unregister($var);

return true;
}

/**
* Initialise session
*/
function pnSessionInit()
{
global $HTTP_SERVER_VARS;

list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

// First thing we do is ensure that there is no attempted pollution
// of the session namespace
foreach($GLOBALS as $k=>$v) {
if (preg_match('/^PNSV/', $k)) {
return false;
}
}

// Kick it
session_start();

// Have to re-write the cache control header to remove no-save, this
// allows downloading of files to disk for application handlers
// adam_baum - no-cache was stopping modules (andromeda) from caching the playlists, et al.
// any strange behaviour encountered, revert to commented out code.
//Header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Cache-Control: cache');

$sessid = session_id();

// Get (actual) client IP addr
$ipaddr = $HTTP_SERVER_VARS['REMOTE_ADDR'];
if (empty($ipaddr)) {
$ipaddr = getenv('REMOTE_ADDR');
}
if (!empty($HTTP_SERVER_VARS['HTTP_CLIENT_IP'])) {
$ipaddr = $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
}
$tmpipaddr = getenv('HTTP_CLIENT_IP');
if (!empty($tmpipaddr)) {
$ipaddr = $tmpipaddr;
}
if (!empty($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) {
$ipaddr = preg_replace('/,.*/', '', $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']);
}
$tmpipaddr = getenv('HTTP_X_FORWARDED_FOR');
if (!empty($tmpipaddr)) {
$ipaddr = preg_replace('/,.*/', '', $tmpipaddr);
}


$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

$query = "SELECT $sessioninfocolumn[ipaddr]
FROM $sessioninfotable
WHERE $sessioninfocolumn[sessid] = '" . pnVarPrepForStore($sessid) . "'";

$result = $dbconn->Execute($query);

if($dbconn->ErrorNo() != 0) {
echo "$query";exit;
return false;
}

if (!$result->EOF) {
// jgm - this has been commented out so that the nice AOL people
// can view PN pages, will examine full implications of this
// later
// list($dbipaddr) = $result->fields;
$result->Close();
// echo "dd";
//echo $sessid;
// if ($ipaddr == $dbipaddr) {
pnSessionCurrent($sessid);
// } else {
// // Mismatch - destroy the session
// session_destroy();
// pnRedirect('index.php');
// return false;
// }
} else {
pnSessionNew($sessid, $ipaddr);

// Generate a random number, used for
// some authentication
srand((double)microtime()*1000000);
pnSessionSetVar('rand', rand());
}

return true;
}

/**
* Continue a current session
* @private
* @param sessid the session ID
*/
function pnSessionCurrent($sessid)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

// Touch the last used time
$query = "UPDATE $sessioninfotable
SET $sessioninfocolumn[lastused] = " . time() . "
WHERE $sessioninfocolumn[sessid] = '" . pnVarPrepForStore($sessid) . "'";

$result = $dbconn->Execute($query);

if ($dbconn->ErrorNo() != 0) {
return false;
}

return true;
}

/**
* Create a new session
* @private
* @param sessid the session ID
* @param ipaddr the IP address of the host with this session
*/
function pnSessionNew($sessid, $ipaddr)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

$query = "INSERT INTO $sessioninfotable
($sessioninfocolumn[sessid],
$sessioninfocolumn[ipaddr],
$sessioninfocolumn[uid],
$sessioninfocolumn[firstused],
$sessioninfocolumn[lastused])
VALUES
('" . pnVarPrepForStore($sessid) . "',
'" . pnVarPrepForStore($ipaddr) . "',
0,
" . time() . ",
" . time() . ")";

$dbconn->Execute($query);

if ($dbconn->ErrorNo() != 0) {
return false;
}

return true;
}

/**
* PHP function to open the session
* @private
*/
function pnSessionOpen($path, $name)
{
// Nothing to do - database opened elsewhere
return true;
}

/**
* PHP function to close the session
* @private
*/
function pnSessionClose()
{
// Nothing to do - database closed elsewhere
return true;
}

/**
* PHP function to read a set of session variables
* @private
*/
function pnSessionRead($sessid)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

$query = "SELECT $sessioninfocolumn[vars]
FROM $sessioninfotable
WHERE $sessioninfocolumn[sessid] = '" . pnVarPrepForStore($sessid) . "'";
$result = $dbconn->Execute($query);

if ($dbconn->ErrorNo() != 0) {
return false;
}

if (!$result->EOF) {
list($value) = $result->fields;
} else {
$value = '';
}
$result->Close();

return($value);
}

/**
* PHP function to write a set of session variables
* @private
*/
function pnSessionWrite($sessid, $vars)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

$query = "UPDATE $sessioninfotable
SET $sessioninfocolumn[vars] = '" . pnVarPrepForStore($vars) . "'
WHERE $sessioninfocolumn[sessid] = '" . pnVarPrepForStore($sessid) . "'";
$dbconn->Execute($query);

if ($dbconn->ErrorNo() != 0) {
return false;
}

return true;
}

/**
* PHP function to destroy a session
* @private
*/
function pnSessionDestroy($sessid)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

$query = "DELETE FROM $sessioninfotable
WHERE $sessioninfocolumn[sessid] = '" . pnVarPrepForStore($sessid) . "'";
$dbconn->Execute($query);

if ($dbconn->ErrorNo() != 0) {
return false;
}

return true;
}

/**
* PHP function to garbage collect session information
* @private
*/
function pnSessionGC($maxlifetime)
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$sessioninfocolumn = &$pntable['session_info_column'];
$sessioninfotable = $pntable['session_info'];

switch (pnConfigGetVar('seclevel')) {
case 'Low':
// Low security - delete session info if user decided not to
// remember themself
$where = "WHERE $sessioninfocolumn[vars] NOT LIKE '%PNSVrememberme|%'
AND $sessioninfocolumn[lastused] < " . (time() - (pnConfigGetVar('secinactivemins') * 60));
break;
case 'Medium':
// Medium security - delete session info if session cookie has
// expired or user decided not to remember
// themself
$where = "WHERE ($sessioninfocolumn[vars] NOT LIKE '%PNSVrememberme|%'
AND $sessioninfocolumn[lastused] < " . (time() - (pnConfigGetVar('secinactivemins') * 60)) . ")
OR $sessioninfocolumn[firstused] < " . (time() - (pnConfigGetVar('secmeddays') * 86400));
break;
case 'High':
default:
// High security - delete session info if user is inactive
$where = "WHERE $sessioninfocolumn[lastused] < " . (time() - (pnConfigGetVar('secinactivemins') * 60));
break;
}
$query = "DELETE FROM $sessioninfotable $where";
$dbconn->Execute($query);

if ($dbconn->ErrorNo() != 0) {
return false;
}

return true;
}
?>

Date : 21 เม.ย. 2550 15:25:02 By : sorajng
 


 

No. 4



โพสกระทู้ ( 126 )
บทความ ( 0 )



สถานะออฟไลน์


Code (JavaScript)
<script type="text/javascript" language="javascript">
window.onbeforeunload = function(){
     if (window.event.clientY < 0 && (window.event.clientX > ( document.documentElement.clientWidth - 5) || window.event.clientX < 15) ) {
          alert("ออกจากระบบ");
          window.location.href = "logout.php";
</script>


แบบนี้ง่ายกว่า แต่ใช้ได้เฉพาะ Internet Explorer Only


ประวัติการแก้ไข
2010-08-13 16:07:49
2010-08-13 16:08:17
Date : 2010-08-13 16:06:36 By : kanjero
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : logout Auto ทำยังไงเราจะให้ logout อัตโนมัติเวลาเราปิดหน้าเว็ปครับ เพราะถ้าไม่ loguot เวลา login เข้า
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่