I've looked in many different forums all day and have not been able to get any help on this matter...hopefully someone here knows.

I'm trying to build a log in script and i've stripped the whole thing down to a simple write to database via SQL but "Start_session()" is flipping out and no one seems to know why. I'm getting these errors:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login2.php:1) in /home/digiconm/public_html/login/login2.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login2.php:1) in /home/digiconm/public_html/login/login2.php on line 2

and this is my php code

<?PHP
session_start();
mysql_connect(localhost,user,pass);
@mysql_select_db(db) or die( "Unable to select database");
$query = "INSERT INTO users VALUES ('','test','test','test','test','test','test','test','','')";
mysql_query($query);
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

and help would be great!

    1. When posting php code, please use the board's [PHP][/PHP] bbcode tags as they make your code much easier to read and analyze. You should go back now and edit your post to include these tags.

    2. Your main problem here is that you can't output anything - that means no spaces, blank lines, etc. - before certain functions (ex. session_start()). Double check that you don't have any blank spaces before the '<?PHP' tag. Also, make sure you're saving the .php script as a plain text file and, if applicable, upload it via FTP in ASCII mode.

    3. Another issue with your script is that you don't properly quote your string paramters. For mysql_connect(), for example, 'localhost', '<username>', etc. are strings, not constants. If you don't surround them in quotes, you're telling PHP that they are constants when, in fact, they are not; this will cause a warning/notice to be generated. Long story shorts: if a parameter is a string, surround it with quotes.

      No spaces, saved as plain .php, changed quotes as below...same errors:

      Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2

      Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2

      <?PHP
      session_start();
      mysql_connect('localhost','user','pass');
      @mysql_select_db('db') or die( "Unable to select database");
      $query = "INSERT INTO users VALUES ('','test','test','test','test','test','test','test','','')";
      mysql_query($query);
      mysql_close();
      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Untitled Document</title>
      </head>

        Can you please rename the script to .txt and attach it to your next post? Don't forget to remove sensitive information, such as your MySQL login credentials (I've been removing these from your posts - you might want to edit that information out before posting!)? I have a feeling it might be that the file was saved in Unicode and a BOM is the culprit, but I can't be sure unless I see the actual file itself.

          The issue is indeed with the encoding of the file. Which editor are you using?

            dreamweaver CS3 and using Expression Web to upload to my server...I didn't know there were different types of encoding for php?!

              It's not the encoding of PHP, it's the encoding of the test in the file itself.

              I don't have CS3 to play around with, but you need to change the file encoding from "UTF-8 with signature" to just plain "UTF-8" (or even just plain "ANSI"). The BOM marker at the beginning is being outputted by the PHP interpreter causing the errors you're getting.

              EDIT: Here is a link to Adobe's online documentation. Follow the instructions to change the default encoding, and make sure that the "Include Unicode Signature (BOM) option" is not checked. If it is, uncheck it.

              Once you change the encoding, note that it won't change the encoding of your existing files (I'm assuming). Thus, you may need to copy and paste your script into a new document to get rid of the BOM marker.

                there's a button that i found that says php encoding and when you click it it pastes

                mb_http_input("utf-8");
                mb_http_output("utf-8");

                into my code...is that what i want to do? if so where in the code should it go?

                  No - as I said, it has nothing to do with PHP's encoding setting. Read my post above - you might have posted before I edited it.

                    Include Unicode Signature BOM is already unchecked...this is what is in that menu...should i change something else?

                      millercj wrote:

                      Include Unicode Signature BOM is already unchecked

                      Are you sure? In the screenshot you sent, it is checked...

                        it wasn't checked but i did find my error...what happend was that i origianally renamed a .html file created in Expression to a .php and it kept the properties...sorry for all the confusion but thank you for your help

                          Write a Reply...