FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Sessions





DanielXP
I can't get my session to last it sets the session and then after tht its gone

below is the code

Code:
case "login":
$username= addslashes($_POST[username]);

$password = md5($_POST[password]);
$info = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());

$data = mysql_fetch_array($info);
if($data[userlevel] == 0) {
echo "This account is banned!";
}
else
if($data[userlevel] == 1) {
echo "This account had not been verified.";
}
else

if($data[password] != $password) {

echo "Incorrect username or password!";

}else{

$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());

$user = mysql_fetch_array($query);

$ip = $_SERVER['REMOTE_ADDR'];
$update = mysql_query("Update users set ip = '$ip' where username = '$logged[username]'");
$_SESSION[id] = $user[id];
$_SESSION[pass] = $user[password];
echo "You are now logged in.";
}
break;
Kaneda
You need to call session_start() before storing any session variables. Actually, you should call it before anything is output. And while it may seem counter-intuitive (from the name of the function), it should be called at the beginning of every page accessing the session variables. In your case, that means whatever page needs to check if the user is logged in, should also call session_start().
DanielXP
Yer

Cheers i forgot about that one

Top off every page my mate told me and i forgot.
DanielXP
It works but now i keep getting this in my shoutbox

Warning: Cannot modify header information - headers already sent by (output started at /home/rmb/public_html/config.php:13) in /home/rmb/public_html/viewtags.php on line 5

Don't have a clue what thats about

EDIT IM USING COOKIES NOW
Kaneda
DanielXP wrote:
It works but now i keep getting this in my shoutbox

Warning: Cannot modify header information - headers already sent by (output started at /home/rmb/public_html/config.php:13) in /home/rmb/public_html/viewtags.php on line 5

Don't have a clue what thats about


Kaneda wrote:
Actually, you should call it before anything is output.


Smile

As soon as PHP outputs something, the response headers (containing information about the content type of the data, whether the content is gzip compressed, cookies etc.) are sent to the browser, so from that moment, you can't modify those headers. session_start() modifies the headers in order to send the cookie containing the user's session ID.

Therefore, session_start() has to be called before any output. Just call it at the very top of the PHP file (the only exception to this is when you're using gzip compression, in which case the function calls implementing that should come before session_start()).
kawkazEE
check your header location code...
Related topics
php sessions
Sessions
PHP: Sessions and Cookies
php sessions
is mutiple login in windows XP simultaneously possible?
FireFox and Cookies/Sessions
php sessions for different accounts
Sessions are deleted fast.
php SESSIONS question
destroy\unset sessions?
Need Help : Dreamweaver sessions
Help with Dreamweaver sessions !!!!!!!!
I need some help please!
Sessions
phpBB sessions
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.