Remis said:
Yeah I already read some books about PHP, including sessions. And Iam practising PHP every day, since several months.
So I could help you with it
Ok, so...
I started recoding my PHP panel. Before it used several pages, but now I wish to use $_GET to arrange the pages.
So banlist.php would become index.php?area=banlist. Alright, I can work the $_GET and I know how to, but I have a problem with the session starting.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\panel\index.php:1) in C:\xampp\htdocs\panel\index.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\panel\index.php:1) in C:\xampp\htdocs\panel\index.php on line 2
I Google'd it up and I found that session_start() must be the first line of the script without whitespace, so I tried several things, such as:
Code:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
...
...
Code:
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
...
...
But still, I get the same 2 errors described before.
What's other to do with sessions is that I use:
Code:
if(session_is_registered("myusername"))
Code:
session_register("myusername");
and bunch of $_SESSION["thing"] operators.
Also, when I do the login, I do like this:
Code:
<?php
if($area == "login")
{
session_register("myusername");
$_POST["myusername"] = $username;
$_POST["mypassword"] = $password;
if(!isset($_POST["myusername"]))
{
$_SESSION["loginerror"] = 'myusername_not_entered';
header("Location: index.php", false);
}
if(!isset($_POST["mypassword"]))
{
$_SESSION["loginerror"] = 'mypassword_not_entered';
header("Location: index.php", false);
}
if(empty($username))
{
$_SESSION["loginerror"] = 'username_empty';
header("Location: index.php", false);
}
if(empty($password))
{
$_SESSION["loginerror"] = 'password_empty';
header("Location: index.php", false);
}
$search = mysql_query("SELECT * FROM `players` WHERE `playername` = '$username'");
if(mysql_num_rows($search) == 0)
{
$_SESSION["loginerror"] = 'account_not_found';
header("Location: index.php", false);
}
if(mysql_num_rows($search) > 1)
{
$_SESSION["loginerror"] = 'really_fucked_up';
header("Location: index.php", false);
}
$row = mysql_fetch_array($search);
if($row["password"] != $password)
{
$_SESSION["loginerror"] = 'password_wrong';
header("Location: index.php", false);
}
$_SESSION["loginerror"] = 'none';
$_SESSION["logged"] = 1;
$_SESSION["username"] = $username;
header("Location: index.php", false);
}
?>
However I get error about the headers already being sent.
So how the **** can I send it from ?area=login to ?area=index with the session shit saved?
I mean the f**king headers are already set, so how?
I don't know where the fuck did those fucking errors jump out from.