By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,929 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,929 IT Pros & Developers. It's quick & easy.

Logout fails to log out

P: n/a
[PHP]
class LoginSessionGenerator extends MethodGenerator {

function LoginSessionGenerator() {}

/**
* Logout
*
* @access public
*/
function &logout() { // STATIC VOID METHOD
global $projectFolderName, $projectURLPath, $willAuthenticate,
$projectAcronym;
if ($willAuthenticate) setcookie("$projectFolderName", '', time() -
86400); // DELETE COOKIE
foreach ($_SESSION as $key => $val) {
if (preg_match("/^${projectAcronym}_/i", $key))
unset($_SESSION[$key]); // DELETE ALL PROJECT SESSION VARIABLES
}
header('Location: http://' . $_SERVER['SERVER_NAME'] .
"$projectURLPath/index.php"); // DEFAULT REDIRECT TO MAIN PAGE
}

}
[/PHP]

.....

[PHP]
if ($_REQUEST['willLogout'])
LoginSessionGenerator::logout();
[/PHP]

For some wacko reason, this class method does absolutely nothing
except redirect. The cookie and session remains intact and
unchanged, even the instance is intact and unchanged.

Could someone help me with this one?

Thanx
Phil
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
so*****@erols.com (Phil Powell) wrote in message
news:<1c**************************@posting.google. com>...

function &logout() {
global $projectFolderName, $projectURLPath, $willAuthenticate,
$projectAcronym;
if ($willAuthenticate) setcookie("$projectFolderName", '', time() - 86400);
foreach ($_SESSION as $key => $val) {
if (preg_match("/^${projectAcronym}_/i", $key)) unset($_SESSION[$key]);
}
header('Location: http://' . $_SERVER['SERVER_NAME'] .
"$projectURLPath/index.php");
} .... For some wacko reason, this class method does absolutely nothing
except redirect. The cookie and session remains intact and
unchanged, even the instance is intact and unchanged.


I can see three potential problems:

1. Is the regular expression working as intended? Does it actually
identify appropriate (or any) session variables?
2. Where is this code running from? Since you are not passing a
path to setcookie(), the amended setting will only be available
in (and under) the current directory.
3. What does $willAuthenticate evaluate to?

Cheers,
NC
Jul 17 '05 #2

P: n/a
It took about 2 days but I finally got it, this works:

[PHP]
/**
* Logout
*
* @access public
* @return mixed HTML (returns HTML only if header() fails)
*/
function &logout() { // STATIC VOID OR HTML STRING METHOD
global $projectFolderName, $projectURLPath, $willAuthenticate,
$projectAcronym;
if ($willAuthenticate) setcookie("$projectFolderName", '', time() -
86400, '/'); // DELETE COOKIE
foreach ($_SESSION as $key => $val) {
if (preg_match("/^{$projectAcronym}_/i", $key)) {
$_SESSION[$key] = '';
unset($_SESSION[$key]); // DELETE ALL PROJECT SESSION
VARIABLES
}
}
global $_SESSION;
header('Pragma: no-cache');
header('Location: http://' . $_SERVER['SERVER_NAME'] .
"$projectURLPath/index.php"); // DEFAULT REDIRECT TO MAIN PAGE
}
[/PHP]
nc@iname.com (Nikolai Chuvakhin) wrote in message news:<32**************************@posting.google. com>...
so*****@erols.com (Phil Powell) wrote in message
news:<1c**************************@posting.google. com>...

function &logout() {
global $projectFolderName, $projectURLPath, $willAuthenticate,
$projectAcronym;
if ($willAuthenticate) setcookie("$projectFolderName", '', time() - 86400);
foreach ($_SESSION as $key => $val) {
if (preg_match("/^${projectAcronym}_/i", $key)) unset($_SESSION[$key]);
}
header('Location: http://' . $_SERVER['SERVER_NAME'] .
"$projectURLPath/index.php");
}

...
For some wacko reason, this class method does absolutely nothing
except redirect. The cookie and session remains intact and
unchanged, even the instance is intact and unchanged.


I can see three potential problems:

1. Is the regular expression working as intended? Does it actually
identify appropriate (or any) session variables?
2. Where is this code running from? Since you are not passing a
path to setcookie(), the amended setting will only be available
in (and under) the current directory.
3. What does $willAuthenticate evaluate to?

Cheers,
NC

Jul 17 '05 #3

P: n/a
so*****@erols.com (Phil Powell) wrote in message
news:<1c**************************@posting.google. com>...

It took about 2 days but I finally got it, this works:

if ($willAuthenticate)
setcookie("$projectFolderName", '', time() - 86400, '/');
As opposed to earlier
if ($willAuthenticate)
setcookie("$projectFolderName", '', time() - 86400);


So it was a path issue after all?

Cheers,
NC
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.