session_start() and header()
Posted: Thu May 20, 2010 7:45 am
Hi!
Before, I had this problem with session_start() - Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users\Administrador\Documents\xampp\htdocs\login.php:1) in C:\Users\Administrador\Documents\xampp\htdocs\login.php on line 3
I've been surfing a bunch of php forums and they all say that i can't have any blank spaces before <?php tag. I've corrected it and now... nothing happens! It doesn't send the error message, but nothing happens!
The purpose is that, after a correct login, it opens a new window with the current user's name. but the new page doesn't open.
If I create a regular html link (with <a>), i manage to open the new page, but the session user name is not sent.
Can anyone help me, please??!
Before, I had this problem with session_start() - Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users\Administrador\Documents\xampp\htdocs\login.php:1) in C:\Users\Administrador\Documents\xampp\htdocs\login.php on line 3
I've been surfing a bunch of php forums and they all say that i can't have any blank spaces before <?php tag. I've corrected it and now... nothing happens! It doesn't send the error message, but nothing happens!
The purpose is that, after a correct login, it opens a new window with the current user's name. but the new page doesn't open.
If I create a regular html link (with <a>), i manage to open the new page, but the session user name is not sent.
Can anyone help me, please??!
Code: Select all
<?php
ob_start();
session_start();
$user= $_POST['user'];
$pwd= $_POST['pwd'];
if ($user && $pwd)
{
$connection = mysql_connect("localhost", "root","") or die("Sem ligação aos registos!");
$db=mysql_select_db("logins",$connection) or die("bd não encontrada!");
$sql = "SELECT * FROM users WHERE username='".$user."'";
$query=mysql_query($sql);
$total=mysql_num_rows($query);
if ($total!=0)
{
$linha=mysql_fetch_assoc($query);
$dbuser=$linha['username'];
$dbpwd=$linha['password'];
if ($dbuser==$user && $dbpwd==$pwd)
{
if (!isset($_SESSION['nome']))
$_SESSION['nome']=$user;
header("Location:lista_users.php");
}
else
{
// several error messages in case user and/or password incorrect
}
?>
<html> settings for background and font </html>