alexkearns Posted July 24, 2012 Share Posted July 24, 2012 I have built a basic CMS for a client's site which works completely, with no errors on WAMPServer PHP 5.3.13 however when I upload it to my live server (PHP 5.3. I get the following errors in my "logincheck" file which checks is a user is logged in or not. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/{myusername}/public_html/{sitename}/cms/home.php:10) in /home/{myusername}/public_html/{sitename}/cms/logincheck.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/{myusername}/public_html/{sitename}/cms/home.php:10) in /home/{myusername}/public_html/{sitename}/cms/logincheck.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/{myusername}/public_html/{sitename}/cms/home.php:10) in /home/{myusername}/public_html/{sitename}/cms/logincheck.php on line 4 Here is the code for the logincheck.php file: <?php session_start(); if (!isset( $_SESSION['myusername'] ) ){ header('location:index.php'); } else{ echo "<div class='phpecho'>". $_SESSION['myusername'] . " " . "successfully logged in :: <a href='logout.php'> log out </a><>"; } ?> Index.php is my login screen And {myusername}, {sitename} are replacements for the correct values in code in light of client privacy. This is the code for my login form's "action". <?php session_start(); include('../../../connectdb.php'); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encryptedmypassword = md5($mypassword); $sql="SELECT * FROM users WHERE Username='$myusername' and Password='$encryptedmypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword $_SESSION['myusername']=$myusername; $_SESSION['mypassword']=$encryptedmypassword; header("location:welcome.php"); } else { header("location:loginfailed.php"); } ?> Please could someone help, Alex Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/ Share on other sites More sharing options...
Jessica Posted July 24, 2012 Share Posted July 24, 2012 http://forums.phpfreaks.com/index.php?topic=37442.0 Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/#findComment-1364084 Share on other sites More sharing options...
alexkearns Posted July 24, 2012 Author Share Posted July 24, 2012 I did read through that, however I could not figure out what was wrong with mine? Dreamweaver has been saving without BOM. Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/#findComment-1364085 Share on other sites More sharing options...
ManiacDan Posted July 24, 2012 Share Posted July 24, 2012 Well, step 1 of figuring out what's wrong with yours is reading the error: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/{myusername}/public_html/{sitename}/cms/home.php:10) in /home/{myusername}/public_html/{sitename}/cms/logincheck.php on line 2 Cannot send header information. Why not? The headers are already sent. Why were the headers sent? output started at /home/{myusername}/public_html/{sitename}/cms/home.php:10 Find that file, find that line, stop outputting. Also, don't run stripslashes on anything, it's deprecated. if your web host requires it, get a new web host which is less than 10 years out of date. You also do not need mysql_real_escape_string on values you'll be running through md5(), and even if you did, you would run it AFTER md5(), not before (but don't run it at all since md5 strings cannot contain sql injection) Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/#findComment-1364095 Share on other sites More sharing options...
alexkearns Posted July 24, 2012 Author Share Posted July 24, 2012 I got it working by changing the location of my logincheck include in my PHP pages, however, now my javascript TinyMCE Text editor does not load and leaves me with blank textboxes! Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/#findComment-1364096 Share on other sites More sharing options...
alexkearns Posted July 24, 2012 Author Share Posted July 24, 2012 The tinymce editor works on my localhost server though with exactly the same code and database. Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/#findComment-1364097 Share on other sites More sharing options...
jazzman1 Posted July 24, 2012 Share Posted July 24, 2012 Open up php.ini file, find the row - output_buffering, and tell us what value is set there ? Quote Link to comment https://forums.phpfreaks.com/topic/266189-php-session-error/#findComment-1364117 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.