MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 23rd, 2004, 07:12 PM
bokerfest bokerfest is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 bokerfest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
php/mysql header and session_start errors

My code all makes perfect sense to to and all the testing for my auth_level is correct and works properly.

My problem when testing the code is that it comes out with error with my session_start(); line and my header("Location: auth2menu.php"); line.

Can Anyone help or tell me what these errors are trying to communicate?

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/oddprod/public_html/login3.php:9) in /home/oddprod/public_html/login3.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/oddprod/public_html/login3.php:9) in /home/oddprod/public_html/login3.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/oddprod/public_html/login3.php:9) in /home/oddprod/public_html/login3.php on line 47

PHP Code:
<?php
//start sessions
session_start();
// Connect to DB
$db mysql_connect ("localhost""username""password")
 or die (
'I cannot connect to the database because: ' mysql_error());
$db_selected mysql_select_db('oddprod_managment'$db);
if (!
$db_selected) {
   die (
'Can\'t use oddprod_managment : ' mysql_error());
}
// End Connect

//extract user information from database

if ($username && $password)
{
 
// if the user has just tried to log in
 
$query "select * from users "
 
."where usersLOGIN='$username' "
 
." and usersPASS='$password' ";
 
$result mysql_query($query);
 
$row mysql_fetch_assoc($result);
 
 if (
mysql_num_rows($result) >0)
 {
  
// if they are in the database register the user id
  
$_SESSION['valid_user'] = $row['usersLOGIN'];
  
$_SESSION['pass'] = $_POST['password'];
  
$_SESSION['auth_level'] = $row["usersTITLEID"];
 }
}

if (
$_SESSION['auth_level']==1){
 
header("Location: auth2menu.php");
}

else if(
$_SESSION['auth_level']==2){
 
header("Location: auth2menu.php");
}

mysql_close($db);

?>

Reply With Quote
  #2  
Old March 24th, 2004, 06:56 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Usually, you'd expect to see this if there was extra space at the top of your file or if this file is included in something that sends some output. Is either of these the case?
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old March 24th, 2004, 07:14 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Can you share with us what's on line 9? You call the session at line 11, and there is some output generated on line 9. You can try to put the session_start() on top of your code, just as in your snippet.
Cheers,
__________________
Work to live, don't live to work

Reply With Quote
  #4  
Old March 24th, 2004, 10:38 AM
bokerfest bokerfest is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 bokerfest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Solution

I got it figured out. I it is because I have html before the php code and the web server confuses the two and thinks I have already submitted header information.

Solution: Take out all previous html to session_start.

Reply With Quote
  #5  
Old March 25th, 2004, 04:46 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
The server confuses nothing. The code is parsed at the moment you call it in your file. But this is exactly what I meant. I struggled with it a long time before I got to the solution. Glad I could help...

Cheers,

Reply With Quote
  #6  
Old March 25th, 2004, 05:23 AM
ChrisIves ChrisIves is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 8 ChrisIves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've seen alot of people adding this line as well:

PHP Code:
 session_start();
header("Cache-control: private"); 


Seems to be some kind of IE6 fix. Thought it was worth mentioning.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > php/mysql header and session_start errors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway