PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
session_start();
function Login($username, $password)
{
// If user was in the middle of filling out new account form,
// and decided to login, then clear all the junk the user filled out.
if ($_SESSION['signup_account']) {
session_destroy(); // line 11
session_start();
}
}
?>
PHP Warning: session_destroy() [<a href='function.session-destroy'>function.session-destroy</a>]: Trying to destroy uninitialized session in /home/username/public_html/checklogin.php on line 11
doesn't it count as session_start() when it's outside of the function? or am i missing something else here?
<?php
session_start();
function Login($username, $password)
{
// If user was in the middle of filling out new account form,
// and decided to login, then clear all the junk the user filled out.
if ($_SESSION['signup_account']) {
session_start();
session_destroy(); // line 11
}
}
?>
yeah, i guess i'll have to try that. unfortunately, its one of those errors that happen only half the time.... so i can't really track it down. but i will try that, thanks tho.
<?php
session_start();
function Login($username, $password)
{
// If user was in the middle of filling out new account form,
// and decided to login, then clear all the junk the user filled out.
if ($_SESSION['signup_account']) {
session_start();
session_destroy(); // line 11
}
}
?>
you'll run into an session already started error on that one.. I personally just do $_SESSION = array(); or alike when wanting to destroy the user's data.
<?php
session_start();
function Login($username, $password)
{
// If user was in the middle of filling out new account form,
// and decided to login, then clear all the junk the user filled out.
if ($_SESSION['signup_account']) {
session_start();
session_destroy(); // line 11
}
}
?>
you'll run into an session already started error as well as some indefined index notice (sometimes) on that one.. I personally just do $_SESSION = array(); or alike when wanting to destroy the user's data.
yeah! i haven't though about it - that's pretty cool, just clearing the whole $_SESSION array on that one... but why does it not recognize the session_start() ?
You have just started the sesson with session_start(); at the top of the code... that makes the $_SESSION global variable array available to the particular php page. But, you need to initialize something as the session variable before you call an session-destory() function.
but I already had session variables stored... if i didn't, it would not have recognized $_SESSION['signup_account'], and would not have called the destroy function. and 'signup_account' is not the only session variable in the session, there are others from other php files.