warning cannot modify header information

Discussion in 'PHP' started by rafiqasad, Dec 27, 2006.

  1. #1
    <?
     //include 'config.php';
     mysql_connect('localhost','rafiq_rafiq','ahm3d');
     mysql_select_db('rafiq_boxty');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<title>Gallagher's Boxty House - Traditional Irish Restaurant - Dublin, Ireland.</title>						
    	    <link href="style.css" rel="stylesheet" type="text/css" />
    	</head>
    <?
    $ch = $_REQUEST['ch'];
    	$submit = $_REQUEST['Submit'];
    	$n = $_REQUEST['name'];
    	$p = $_REQUEST['pass'];
    	if($submit == 'Login')
    	{
    		if( empty($n) && empty($p))
    		{
    			header("location:index.php?ch=eb");
    		}
    		else if(empty($n))
    		{
    			header("location:index.php?ch=en");
    		}
    		else if(empty($p))
    		{
    			header("location:index.php?ch=ep");
    		}
    		else
    		{
    			$sql = "SELECT * FROM _users WHERE login = '$n'";
    			$result = mysql_query($sql);
    			if(mysql_num_rows($result) <=0 )
    			{
    				header("location:index.php?ch=nu");
    			}
    			else
    			{
    				$p = md5($p);
    				$sql = "SELECT * FROM _users WHERE passwd = '$p'";
    				$result = mysql_query($sql);
    				if(mysql_num_rows($result) <=0 )
    				{
    					header("location:index.php?ch=wp");
    				}
    				else
    				{
    					$result = mysql_fetch_array($result);
    					$name = $result['name'];
    					//echo $name.'<br>';
    					//echo $passw.'<br>';
    					ob_start();
    					session_start();
    					//session_register();
    					session_register('id');
    					session_register('name');
    					//echo session_id();
    					$_SESSION['id'] = session_id();
    					$_SESSION['name'] = $name;
    					$ids = $_SESSION['id'];
    					//echo $ids;
    					//echo $_SESSION['id'].'<br/>';
    					//echo $_SESSION['name'].'<br/>';
    					$start=time(); 
    				    $_SESSION['time_start']=$start; 
    					header("location:after_login2.php");
    					
    				} 
    			}
    		}
    		
    	}	
    ?>
    
    
    	<body OnLoad="document.login.name.focus();">
    		<table class="toptable" border="0" cellspacing="0" cellpadding="0">
    		<tr>
    		<td align="center" height="75%" valign="top">
    		  	<table class="maintable" border="0" cellspacing="3" cellpadding="0">
    				<tr>
    					<td colspan="2" id="header">
    						<? include('header.php'); ?>
    
    					</td>
    					
    				</tr>
    				<tr>
    					<td valign="top"  class="contentarea" style="padding-top:105px;">
    
    						<table width="100%" border="0" cellspacing="0" cellpadding="3">
    							
    							<tr>
    								<td colspan="2" valign="middle" align="center">
    									<form method="post" name="login" action="<?=$_SERVER['PHP_SELF']?>">
    									<table width="300" border="0" cellspacing="0" cellpadding="1" class="datafield">	
    													
    										<tr>
    											<td colspan="2" class="heading">Login</td>
    										</tr>
    										<tr>
    											<td class="error" colspan="2">
    											 <?
    												if($ch == 'eb')
    												{
    													echo 'Empty Both  field';
    												}
    												else if($ch == 'en')
    												{
    													echo 'Empty User Name field';
    												}
    												else if($ch == 'ep')
    												{
    													echo 'Empty Password field';
    												}
    												else if($ch == 'nu')
    												{
    													echo 'User Not Found';
    												}
    												else if($ch == 'wp')
    												{
    													echo 'Password Not Match';
    												}
    												else
    												{
    													echo '<br/>';
    													echo '&nbsp;';
    												}
    	 										 ?>
    											</td>
    										</tr>	
    										
    										<tr>
    											<td align="right">User ID:</td>
    											<td align="left"><input type="text" name="name" /></td>
    										</tr>
    										<tr><td height="5"></td></tr>
    										<tr>	
    											<td align="right">Password:</td>
    											<td align="left"><input type="password" name="pass" /></td>
    											
    										</tr>
    										<tr><td height="5"></td></tr>
    										<tr>
    											<td></td>
    											<td align="left">
    												<input type="submit" value="Login" class="button" name="Submit"/>
    											</td>
    										</tr>
    										<tr>
    											<td colspan="2" align="center">Forgot Password? <a href="forget.php">Click Here</a> </td>
    										</tr>
    										<tr><td>&nbsp;</td></tr>
    									</table>
    									</form>
    								</td>
    							 </tr>
    						</table>
    					</td>
    				</tr>
    				<? include('footer.php')?>
    			</table>
    		</td>
    		</tr>
    		</table>
    
    	
    	
    	
    	</body>
    </html>
    PHP:

    when i locally run this file no warning and login properly but when upload on server fail to login and there are two warnings
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/rafiq/public_html/admins/index.php:12) in /home/rafiq/public_html/admins/index.php on line 55

    Warning: Cannot modify header information - headers already sent by (output started at /home/rafiq/public_html/admins/index.php:12) in /home/rafiq/public_html/admins/index.php on line 68


    please some one solve my this problem
     
    rafiqasad, Dec 27, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    session_start needs to be called before anything that outputs text to the browser, ie echo statements and html

    headers need to be sent in the same way before any html is output to the browser, do your php headers and session start above the html and you should be okay
     
    krakjoe, Dec 27, 2006 IP
  3. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    remove any blank lines in your html code
     
    maiahost, Dec 27, 2006 IP
  4. frisby

    frisby Well-Known Member

    Messages:
    1,378
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Put header of html file after php code.
     
    frisby, Dec 27, 2006 IP
  5. Makis77

    Makis77 Well-Known Member

    Messages:
    298
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    120
    #5
    also think of saving ur file with NO BOM
    marks...
     
    Makis77, Dec 27, 2006 IP
  6. p2y

    p2y Well-Known Member

    Messages:
    581
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    123
    #6
    you cannot send headers after html code :) u should send headers first , before html code ;)
     
    p2y, Dec 27, 2006 IP