When i used session_auto_start=1 flag in my php.ini, my site worked OK.
Now i moved it to host (session_auto_start=0, and ,of course, i can not change it). I added session_start() function in my login.php, but sessions do not start.
Any suggestions?
Thanks
Session_start() doesn't work
Moderator: General Moderators
No errors, no messages, just session variables, registered in login.php, are invisible in the another .php files(members pages).
If i understand correctly, start_session() must be first function in the site? Or first php function in the file?
Sorry, i'm really newbie in php.
Thank you very much for your help
If i understand correctly, start_session() must be first function in the site? Or first php function in the file?
Sorry, i'm really newbie in php.
Thank you very much for your help
Thanks ! 
It was very important : use session_start() for each page(i used it only at the first
)
But now i have a new problem : only second "Submit" of the Login form starts the session.
This is my code(short version).
[mod_edit:
It was very important : use session_start() for each page(i used it only at the first
But now i have a new problem : only second "Submit" of the Login form starts the session.
This is my code(short version).
Code: Select all
<?
session_start();
// MySQL connection
?>
<html>
<head><title>Login</title></head>
<body>
<?
if(!isset($usernameU) | !isset($passwordU)) {
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<table><tr><td>
<table>
<tr><td Password :</td>
<td><input type=password name=passwordU></td></tr>
<input type=submit value=Submit></td></tr>
</form>
</td></tr></table>
</td></tr></table>
</body>
</html>
<?
exit();
}
session_register("usernameU");
session_register("passwordU");
$sql = mysql_query("SELECT password FROM login WHERE username = '$usernameU'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $passwordU == $fetch_em["password"]) {
$valid_user = 1;
}
else {
$valid_user = 0;
}
if ($valid_user)
{//return to main page
}
if (!($valid_user))
{
session_unset(); // Unset session variables.
session_destroy();
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<table><tr><td>
<table >
<tr><td>
Incorrect login information, please try again.
</td></tr>
<tr><td>User Name :</td><td>
<input type=text name=usernameU></td></tr>
<tr><td>Password :</td>
<td><input type=password name=passwordU></td></tr>
<tr><td>
<input type=submit value=Submit></td></tr>
</form>
</td></tr></table>
</td></tr></table>
</body>
</html>
<?
exit();
}
?>Code: Select all
tag added][/size]
What did i do wrong?