Page 1 of 2
I need to make log out page from my session area
Posted: Fri Dec 29, 2006 2:49 pm
by ms_dos10
Hi all , I need to make log out page from my session area , How can i do that ?
Code: Select all
<?php
if($_SESSION['sessref'])
{
session_unregister($_SESSION['sessref']);
//session_unset();
session_destroy();
header("location:admin.php");
}
?>
Posted: Fri Dec 29, 2006 2:50 pm
by daedalus__
You just posted code that should work?
Posted: Fri Dec 29, 2006 2:52 pm
by John Cartwright
You might want to read the cautions on session_unregister() manual page.
but to answer your question I would simply erase the session by overwritting it with a blank array.
If you want to unset specific variables that flag whether or not they are logged in, you can use unset() or set the variable to false depending how your system is setup.
Posted: Fri Dec 29, 2006 3:03 pm
by ms_dos10
I'm get log out page blank and doesn't send me to admicp.php page .
i think header function doesn't work or what ?
And can you tell me with code it'll help me more and butter
Posted: Fri Dec 29, 2006 3:08 pm
by RobertGonzalez
Read the manual on
header() as a redirect tool as it is pretty clear that you should A) use a complete URI and B) follow it with exit;.
There is really no need to use session_unregister. Use
unset() like Jcart mentioned, or, like he also mentioned, reset the $_SESSION super global array to an empty array.
Posted: Fri Dec 29, 2006 3:10 pm
by John Cartwright
ms_dos10 wrote:I'm get log out page blank and doesn't send me to admicp.php page .
i think header function doesn't work or what ?
Try calling session_write_close(); before sending the header. Secondly, you might want to call exit() after sending the header(). Thirdly, some browsers won't understand relative links, so use the full path instead.
If that doesn't work, you might have a parse error with display error's turned off. You might want to double check your php.ini file for display_errors.
ms_dos10 wrote:
And can you tell me with code it'll help me more and butter
Nope, but you can try it for yourself and we'll nudge you when needed.
Posted: Fri Dec 29, 2006 3:19 pm
by ms_dos10
first am tried like this
Code: Select all
<?php
if($_SESSION['sessref'])
{
$_SESSION['sessref'] = array();
session_unset();
session_destroy();
header("location:admin.php");
exit();
}
?>
and like this again
Code: Select all
<?php
if($_SESSION['sessref'])
{
$_SESSION = array();
session_unset();
session_destroy();
header("location:admin.php");
exit();
}
?>
doesn't work same result i get in log out page as blank and doesn't send me to admincp.php
i don't have that much in php "experience "
Posted: Fri Dec 29, 2006 3:23 pm
by John Cartwright
I suggest you re-read the above posts word for word.
A couple things you should have done, remove the session_* functions, use complete url's for redirecting, and
run the following in a new file on each server and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
Posted: Fri Dec 29, 2006 3:25 pm
by RobertGonzalez
Is the sessref var set? You should check that. Also, you should read the manual on
session_destroy() as there is a logout reference in the description of the function.
Posted: Fri Dec 29, 2006 3:31 pm
by ms_dos10
this is the result
PHP Version: 5.0.5
PHP OS: WINNT
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
bcmath calendar com_dotnet ctype
ftp iconv odbc pcre
session SPL SQLite standard
tokenizer zlib libxml dom
SimpleXML wddx xml apache2handler
dbase dbx dio filepro
gd mbstring exif mime_magic
ming msql mssql mysql
mysqli openssl pdf shmop
soap sockets zip Zend Optimizer
How can i but complete url am in local host , i'll tell what i know . i have to write the complete ur when i move to real time or that not correct . and how can i write that url in the local host
Posted: Fri Dec 29, 2006 3:37 pm
by RobertGonzalez
If you are in localhost, you use localhost as the domain. I would suggest that you either set an application-wide variable that you reference with your current hostname, or do a check on the hostname to findout if it is local. But really all you need to do is...
Code: Select all
<?php
header('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_FILENAME']) . 'somepage.php');
exit;
?>
Posted: Fri Dec 29, 2006 3:51 pm
by ms_dos10
Yup it's local host and am getting crazy same nothing change
Code: Select all
<?php
if($_SESSION['sessref'])
{
$_SESSION = array();
session_unset();
session_destroy();
header('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['web/student']) . 'admincp.php');
exit();
}
?>
Posted: Fri Dec 29, 2006 3:52 pm
by RobertGonzalez
Is your server apache or IIS?
Posted: Fri Dec 29, 2006 3:57 pm
by ms_dos10
apache server , it's xampp component that what am using
Posted: Fri Dec 29, 2006 4:12 pm
by RobertGonzalez
Instead of headering, try echoing something just to make sure the script works. And remember to clear your browser cache.