ra_ie_darkness Posted November 15, 2011 Share Posted November 15, 2011 I am trying to create an index page which contains registration and login field the problem that i get is on successful login a warning is displayed session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Eventz.com\index.php:116) in C:\xampp\htdocs\Eventz.com\index.php on line 235 This is the login part of my index.php this tag is inside an html table below the login form I also have a registration form and its php code above the login form <?php if (isset($_REQUEST['pass'])) { $id=$_POST['id']; $pass=$_POST['pass']; $conn =mysql_connect("localhost","root",""); if (!$conn) { die('Could not connect: ' . mysql_error()); } /* checking connection....success! */ $e=mysql_select_db('test', $conn); if(!$e) { die(''.mysql_error()); } else { echo 'database selected successfully'; } if (isset($_REQUEST['id']) || (isset($_REQUEST['pass']))) { if($_REQUEST['id'] == "" || $_REQUEST['pass']=="") { echo "login fields cannot be empty"; } else { $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'"); $count=mysql_num_rows($sql); if($count==1) /* $count checks if username and password are in same row */ { session_start(); $_SESSION['id']=$id; echo "</br>Login Successful</br>"; } else { echo "</br>invalid</br>"; echo "please try to login again</br>"; } } } } ?> Any help or suggestion would be appreciated Quote Link to comment Share on other sites More sharing options...
kicken Posted November 15, 2011 Share Posted November 15, 2011 this tag is inside an html table below the login form I take it that means there is HTML above this block of PHP code? You can't call session_start after you have sent output (which includes anything, even blank space) which is outside of <?php ?> tags. Reason is session-start() has to send headers for the cookie, and sending output causes the headers to be sent which means you can't send any new headers after that point. You need to move your processing code to be at the top of the script, before any other output. see also, the sticky on header errors Quote Link to comment Share on other sites More sharing options...
ra_ie_darkness Posted November 15, 2011 Author Share Posted November 15, 2011 I understand that but I want display the login status message below the login button how can i do that Quote Link to comment Share on other sites More sharing options...
cypher86 Posted November 15, 2011 Share Posted November 15, 2011 usually the structure of a login form is as follows: login_form.html-->check_login.php-->or-->login_success.php-->you are logged in. ^------------------------------------| Quote Link to comment 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.