Connecting Tech Pros Worldwide Help | Site Map

Problems with a login page! Need Help!

  #1  
Old June 24th, 2009, 04:47 PM
mideastgirl's Avatar
Member
 
Join Date: Jun 2009
Location: Indiana
Posts: 65
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 5

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 24

This is the code I am using:
<?php
ob_start();
// first, let's destroy the previous session just in case it wasn't beforehand
// the new session will start at the news-edit page
session_start();

header("Cache-control: private"); //IE 6 Fix

set_time_limit(600);

include("admin-dbcon.php");

//Check to see if the username and password is valid (if it is in the database)
$validate = mysql_query("select * from admin_login where username = '$_POST[username]' and password = '$_POST[password]'");

$isvalid=mysql_num_rows($validate);

//if valid login send on, if not send to error page
if ($isvalid != 0) {
$_SESSION['username'] = $_POST[username];
while ($row=mysql_fetch_array($validate)){
$_SESSION['userid']=$row["ID"];
}
header("Location: admintasks.php");
}
//else {
// header("Location: login-error.php");
//}
?>

Last edited by mideastgirl; June 24th, 2009 at 04:49 PM. Reason: header already sent, session_start(), connot modify header
  #2  
Old June 25th, 2009, 08:06 AM
Administrator
 
Join Date: Sep 2006
Posts: 12,084

re: Problems with a login page! Need Help!


The problem you have is a PHP problem not a MySQL problem.
Basically session_start() must be called before you output anything and you must make sure that it is not called twice (e.g. if you are including a file in another file).
The error message also tells you exactly which lines of code are outputting something before calling session_start();
Also read the PHP manual for those functions before using them.
  #3  
Old June 30th, 2009, 11:35 AM
Member
 
Join Date: Dec 2007
Posts: 47

re: Problems with a login page! Need Help!


It looks as if this code is being called from another php file....

If so the ob_start(); should be at the top of the file calling this along with the session_start(); and removed from the code sent.

Session error looks like its saying that session has already been started and the header error is saying that output has already been sent to the browser.

Guessing yout main script has outputed something then called this??


Quote:
if ($isvalid != 0) {
$_SESSION['username'] = $_POST[username];
while ($row=mysql_fetch_array($validate)){
$_SESSION['userid']=$row["ID"];
}
header("Location: admintasks.php");
}
This should be something like this
Expand|Select|Wrap|Line Numbers
  1. if ($isvalid == 1) {
  2.     $_SESSION['username'] = $_POST[username];
  3.     $_SESSION['userid']=mysql_result($isvalid, "ID");
  4.  
  5.     header("Location: admintasks.php");
  6. else if($isvalid > 1)
  7. {/*ERROR code here*/}
As what if there were multiple lines with the same username?

If you are going to use the fetch array loop method you need mysql_fetch_assoc not mysql_fetch_array.
Reply

Tags
headers already sent, session_start()


Similar Threads
Thread Thread Starter Forum Replies Last Post
session problem with login script Tom answers 2 April 25th, 2006 08:45 AM
Login Page Problem; Click Events not fired amit.purohit answers 10 November 22nd, 2005 02:36 PM
Have not all the pages protected by the login page Philippe Meunier answers 1 November 17th, 2005 10:37 PM
Login Page Problem; Click Events not fired amit.purohit answers 10 July 21st, 2005 06:45 PM
Problems with DataSources using JNDI and MySQL Jon Dellaria answers 2 July 17th, 2005 10:50 PM