Jump to content

What is this error? code worked in live server but not working in localhost


SUNIL16

Recommended Posts

What is this error?

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\jaga\login.php:9) in C:\xampp\htdocs\jaga\login.php  on line 12

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\jaga\login.php:9) in C:\xampp\htdocs\jaga\login.php on line 12

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\jaga\login.php:9) in C:\xampp\htdocs\jaga\login.php on line 37

 

Why it is showing?

 

below is my code

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Login Page</title>
<?php

require("config.php");
session_start();
if ($_POST['submit']=='login')
{
$username="$_POST[username]";
$password="$_POST[password]";
$sql="SELECT username FROM users where username='$username' AND password='$password'";
$result = mysql_query($sql) or die (mysql_error()); 
$num = mysql_num_rows($result);

    if ( $num != 0 ) { 

        // A matching row was found - the user is authenticated. 
        
   list($username) = mysql_fetch_row($result);
	// this sets variables in the session 
	$_SESSION['user']= $username;  

	header("Location: Content.html");
	//echo "Logged in...";
	exit();
    } 
   
header("Location: login.php?msg=Invalid Login");	
}
?>

</head>

<body>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="325">
  <tr>
    <td width="100%" height="114"><font size="7">Login Page</font></td>
  </tr>
  <tr>
    <td width="100%" height="178">Login:<div align="center">
      <center>
  <p><?php if(isset($_GET[msg]))
  {
	  echo $_GET[msg];
  }?>
  </p>
<form name="form1" method="post" action="">
      <table border="1" cellpadding="4" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="51%">
        <tr>
          <td width="36%" align="center">Username:</td>
          <td width="64%" align="center"><input type="text" name="username" size="28"></td>
        </tr>
        <tr>
          <td width="36%" align="center">Password:</td>
          <td width="64%" align="center"><input type="password" name="password" size="28"></td>
        </tr>
        <tr>
          <td width="100%" align="center" colspan="2">
	  <input type="submit" name="submit" value="login">
      
          </td>
        </tr>
      </table>
            </form>
      </center>
    </div>
    </td>
  </tr>
  <tr>
    <td width="100%" height="31"> </td>
  </tr>
</table>

</body>

</html>

Link to comment
Share on other sites

your live server was set to not display warnings. You localhost is set to show them. They were there you just couldn't see them.

 

You have output either in your config.php or in this  file before the session_start();

 

probably the extra line between <html> and <head>. But could be something in your config.php also.

 

 

Link to comment
Share on other sites

PHP code does not need to be placed within the HTML head tags. Move your PHP code before the <html> tag, eg

 

<?php

require("config.php");
session_start();
if ($_POST['submit']=='login')
{
   $username="$_POST[username]";
   $password="$_POST[password]";
$sql="SELECT username FROM users where username='$username' AND password='$password'";
$result = mysql_query($sql) or die (mysql_error()); 
$num = mysql_num_rows($result);

    if ( $num != 0 ) { 

        // A matching row was found - the user is authenticated. 
        
      list($username) = mysql_fetch_row($result);
      // this sets variables in the session 
      $_SESSION['user']= $username;  
   
      header("Location: Content.html");
      //echo "Logged in...";
      exit();
    } 
   
header("Location: login.php?msg=Invalid Login");   
}
?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Login Page</title>

 

You cannot use session_start or header before any output is sent to the browser. Moving the php code to the top of the page will fix your error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.