Jump to content

Recommended Posts

Hey guys,

 

I installed Xampp yesterday and I am still getting the following error message with the PHP code which I did not have before I installed xampp so i was just wondering why i am getting this error now? I also have the session_start at the top of the code.

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\processUpload.php:4)

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/55617-php-error-message-again/
Share on other sites

Hi, I can't seem to find the problem, can you see it in the code? Sorry about the tabs they messed up when i copied the code.

 

<html>
<head>
<title>pu</title>
<style type="text/css">
<!--
.style1{font-family: Arial, Helvetica, sans-serif}
-->
</style>
</head>
<body bgcolor="#CCCCCC">
<p align="center" style="style1">

<?php
session_start();
include('db.php');
$link_id = db_('');


$fl = "uw/";


$fl = $fl.$HTTP_POST_FILES['gf']['na'];

$mn= $HTTP_POST_VARS['mn'];
$pa = $fl;
$an = $HTTP_POST_VARS['an'];
$at = $HTTP_POST_VARS['at'];


if(move_uploaded_file($HTTP_POST_FILES['gf']['tn'], $fl))
  	{
    	
	$gu = "SELECT ui FROM up WHERE pa = '$fl'";
	$re = mysql_query($gu, $link_id);

		if(mysql_num_rows($re) > 0 )
		{
?>
			<p align="center" class="style1">
                               <?php echo "already exists"; ?>


			</p>
			 <p align="center" class="style1"><a href="uw.php" class="style6">Back </a></span></p>
			 <p align="center" class="style1"><a href="lo.php" class="style6">Logout</a></span></p>
<?php
			exit();

		}

	$iu="INSERT INTO upload VALUES('','$mn','$pa', '$an', '$at')";
	mysql_query($iu, $link_id);
?>

	<p align="center" class="style1">
          	<?php echo "The selected file ".$HTTP_POST_FILES['gf']['na']. "";?> </p>

<?php
		 }
  	 			else
     	 				{
?>
	  		 <p align="center" class="style1">
			<?php echo "the file does not exist.";?>
			</p>
			 <p align="center" class="style1"><a href="uw.php" class="style1">Back </a></span></p>
			 <p align="center" class="style1"><a href="lo.php" class="style1">Logout</a></span></p>
<?php
			exit();
     	 				}
?>


</p>

  <p align="center" class="style1">Please click the following:</p>
  <p align="center" class="style1"><a href="ah.php">Home</a></p>
   <p align="center" class="style1"><a href="lo.php">Logout</a></p>

</body>
</html>

You need to start the session before anything else is sent. Once you close the <head> tag (or echo something) then the headers have been sent.

 

<?php

session_start();
include('db.php');
$link_id = db_('');

?><html>
<head>
<title>pu</title>
<style type="text/css">
<!--
.style1{font-family: Arial, Helvetica, sans-serif}
-->
</style>
</head>
<body bgcolor="#CCCCCC">
<p align="center" style="style1">

<?php

$fl = "uw/";


$fl = $fl.$HTTP_POST_FILES['gf']['na'];

$mn= $HTTP_POST_VARS['mn'];
$pa = $fl;
$an = $HTTP_POST_VARS['an'];
$at = $HTTP_POST_VARS['at'];


if(move_uploaded_file($HTTP_POST_FILES['gf']['tn'], $fl))
  	{
    	
	$gu = "SELECT ui FROM up WHERE pa = '$fl'";
	$re = mysql_query($gu, $link_id);

		if(mysql_num_rows($re) > 0 )
		{
?>
			<p align="center" class="style1">
                               <?php echo "already exists"; ?>


			</p>
			 <p align="center" class="style1"><a href="uw.php" class="style6">Back </a></span></p>
			 <p align="center" class="style1"><a href="lo.php" class="style6">Logout</a></span></p>
<?php
			exit();

		}

	$iu="INSERT INTO upload VALUES('','$mn','$pa', '$an', '$at')";
	mysql_query($iu, $link_id);
?>

	<p align="center" class="style1">
          	<?php echo "The selected file ".$HTTP_POST_FILES['gf']['na']. "";?> </p>

<?php
		 }
  	 			else
     	 				{
?>
	  		 <p align="center" class="style1">
			<?php echo "the file does not exist.";?>
			</p>
			 <p align="center" class="style1"><a href="uploadWork.php" class="style1">Back </a></span></p>
			 <p align="center" class="style1"><a href="logout.php" class="style1">Logout</a></span></p>
<?php
			exit();
     	 				}
?>


</p>

  <p align="center" class="style1">Please click the following link to go to back to the admin home page:</p>
  <p align="center" class="style1"><a href="adminHome.php">Home</a></p>
   <p align="center" class="style1"><a href="logout.php">Logout</a></p>

</body>
</html>

Yes it applies to all versions of PHP. You probably didn't see that error last time because your PHP4 setup had display_errors set to off so you didn't see the error - however you would of gotten a blank page instead. Or your PHP4 setup had output buffering enabled in the php.ini

Yes it applies to all versions of PHP. You probably didn't see that error last time because your PHP4 setup had display_errors set to off so you didn't see the error - however you would of gotten a blank page instead. Or your PHP4 setup had output buffering enabled in the php.ini

 

Thanks again :)

 

Am I best having output buffering enabled in the php.ini file? and is it also good practice to put the following code at the top of all the pages to avoid problems?

 

<?php session_start(); ?>

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.