Page 1 of 1
Simple Login problem
Posted: Tue Aug 25, 2009 10:09 am
by klevis miho
I'm doing a login with sessions. I created a database, with id, username and password.
Code: Select all
<?php
include('../includes/connection.php');
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$result = mysql_query("SELECT * FROM perdorues WHERE username='$user' AND password='$pass'");
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0) {
while($row = mysql_fetch_array($result)) {
session_start();
session_register('username');
echo 'Success';
}
} else {
echo 'Incorrect login name or password';
}
?>
And it displays me that error:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\fjalor\includes\connection.php:6) in C:\xampp\htdocs\fjalor\admin\login.php on line 12
Success
Any help would be appreciated
Re: Simple Login problem
Posted: Tue Aug 25, 2009 10:32 am
by jackpf
Connection.php is outputting something. Put session_start() at the top of the script.
Also, since it's in a while loop, if multiple rows are returned, you'll be calling session_start() multiple times...which you'r enot supposed to do.
Re: Simple Login problem
Posted: Tue Aug 25, 2009 10:46 am
by klevis miho
Here the code again with the connection included, i also tried putting session_start() on the top:
Code: Select all
<?php
$connection = mysql_connect('localhost','root','') or die(mysql_error());
$selectDB = mysql_select_db('fjalorinformatike') or die(mysql_error());
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$result = mysql_query("SELECT * FROM perdorues WHERE username='$user' AND password='$pass'");
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0) {
while($row = mysql_fetch_array($result)) {
session_start();
session_register('username');
echo 'Success';
}
} else {
echo 'Incorrect login name or password';
}
?>
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\fjalor\admin\login.php:1) in C:\xampp\htdocs\fjalor\admin\login.php on line 2
Success
PS. It's just one row in the database
Re: Simple Login problem
Posted: Tue Aug 25, 2009 12:09 pm
by jackpf
You still haven't put it at the top.
Also, if there's only 1 row, you don't need the while loop.
Re: Simple Login problem
Posted: Tue Aug 25, 2009 1:50 pm
by klevis miho
Ok man im here now:
Code: Select all
<?php
session_start();
$connection = mysql_connect('localhost','root','') or die(mysql_error());
$selectDB = mysql_select_db('fjalorinformatike') or die(mysql_error());
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$result = mysql_query("SELECT * FROM perdorues WHERE username='$user' AND password='$pass'");
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0) {
$row = mysql_fetch_array($result);
session_register('username');
echo 'Success';
} else {
echo 'Incorrect login name or password';
}
?>
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\fjalor\admin\login.php:1) in C:\xampp\htdocs\fjalor\admin\login.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\fjalor\admin\login.php:1) in C:\xampp\htdocs\fjalor\admin\login.php on line 2
Success
It must be a session thing. Im trying to learn sessions by that u know

Re: Simple Login problem
Posted: Tue Aug 25, 2009 9:27 pm
by ageofturb
Remember that you always need to put these things:
headers, session functions, cookies...
Code: Select all
header("xxx");
session_start(); session_destroy();
setCookie("xx");
before anything is output.
so put them before any HTML or any echo.
___________
Cheers
blues all we want!
Re: Simple Login problem
Posted: Wed Aug 26, 2009 12:54 am
by klevis miho
I got the problem, it was that space before the <?php . What an errorr lol
Re: Simple Login problem
Posted: Wed Aug 26, 2009 6:27 am
by jackpf
Output includes white space
