class - Why am I getting this PHP session_start() error? -


I did not know why I was getting this session error ...

Warning: Session_start () [function.session-start]: Sessions can not send cache limiter - Headers have already been sent (output C: \ webserver \ htdocs \ project2 \ labs \ form-submits \ index.php: 2 ) In C: \ webserver \ htdocs \ project2 \ labs \ form-submits \ index.php on line 2

As far as I knew that this occurs when in the first browser of the session There are some types of output called the session_start () function Power, appeared on the screen before the call in this case is nothing, not even any white space. Any ideas why I still get errors?

I have posted the full source code of this demo so that you can see what I used to create the error.

  & lt ;? Php session_start (); Required ('formkey.class.php'); $ FormKey = new form (); $ Error = 'no error'; // request? If ($ _ server ['REQUEST_METHOD'] == 'post') {// Validate the form key (!! Isset ($ _ POST ['form_key']) !! $ FormKey- & gt; Valid ()) { // form key is invalid, an error $ error = 'show form key error!'; } Else {// your remaining verification here $ error = 'no form key error!'; }}? & Gt; & Lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD XHTML 1.0 Stronger // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en" lang = "en" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Secure form with form keys & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div & gt; & Lt ;? Php if ($ error) {echo ($ error); }? & Gt; & Lt; Form action = "" method = "post" & gt; & Lt; DL & gt; & Lt ;? Php $ formKey- & gt; Output (); ? & Gt; & Lt; Dt & gt; & Lt; Label = "username" & gt; Username: & lt; / Label & gt; & Lt; / Dt & gt; & Lt; Dd & gt; & Lt; Input type = "text" name = "username" id = "user name" /> gt; & Lt; / Dd> & Lt; Dt & gt; & Lt; Label = "username" & gt; Password: & lt; / Label & gt; & Lt; / Dt & gt; & Lt; Dd & gt; & Lt; Input type = "password" name = "password" id = "password" /> gt; & Lt; / Dd> & Lt; DT & gt; & Lt; / Dt & gt; & Lt; Dd & gt; & Lt; Input type = "submit" value = "submit" /> & Lt; / Dd> & Lt; DL & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

class file

  & lt ;? Php class formKey {// Here we store the personal $ formKey key of the generated form; // Here we store the old form key private $ old_formKey; // Constructor stores our key in the variable variable __construct () {//, we need the first key, so we store it if (isset ($ _ session ['form_key']) {$ This- & gt; old_forma = $ _SESSION ['form_key'];}} function to generate the main personal function of the function (genericName) {$ ip = $ _SERVER ['REMOTE_ADDR']; $ Uniqid = uniqid (Mt_rand (), true); Return md5 ($ ip. Uniqid);} // Function key to output out as public function output Generate () {// key and within square $ - gt; formKey = $ this-> GenerateKey (); // session $ _SESSION ['form_key'] = $ this- & gt; form Store the form key in; // resize the output form key "input type = 'hidden' name = 'form_key' id = 'form_key' value = ''. $ $ - form-ky. '' / / Gt; ";} // function that the key of the form validates the public data posted data () {// We use the old form and do not use the newly generated version ($ _ POST ['f Orm_key '] == $ this- & gt; Old_form) {/ Key is valid, come back true. Back true; } Else {// key is invalid, false return details is false; }}}? & Gt;  

Once I start a BOM (byte order marker) file It is obvious that due to this there was also the reason for sending the header, however, it could be a php bug that has been done properly though it is worth taking a look.

Edit Do: At this point, I am thinking that session_start () is throwing an error before sending the cookie. An initial error will be sent to the browser and sent to the cookie. However, in this case, you should see the first error on your screen. I know this is probably not an issue, but I can not think what the problem might be.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -