Jump to content

[SOLVED] Output Starting on Line 1 - "<?php" is the only thing on line 1


Recommended Posts

Hi folks,

 

I'm having some problems with a script I'm writing. I'm trying to use a session to store POST variables for another page, then redirect based on one of the post variables. After the user redirects, they click a few links, and come back to the redirecting page, except they see the content this time, with some form fields pre-populated using the session info.

 

Here are the error codes I get:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/dir/public_html/orderconfirm.php:1) in /home/dir/public_html/orderconfirm.php on line 1

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/dir/public_html/orderconfirm.php:1) in /home/dir/public_html/orderconfirm.php on line 1

 

Warning: Cannot modify header information - headers already sent by (output started at /home/dir/public_html/orderconfirm.php:1) in /home/dir/public_html/orderconfirm.php on line 16

 

Here is the code at the top of the page responsible for the work(starting from line 1)

<?php session_start();
if (isset($_POST))
{
if ($_GET['us'] != 'true')
{	
	foreach ($_POST as $key => $value)
		$_SESSION[$key] = $value;

}

for ($i=1;$i<20;$i++)
{
	if(isset($_POST['sku'.$i]))
	{
		if ($_POST['sku'.$i] == "AOI0000")
			header('Location: http://www.sitename.com/bookthankyou.php');
		elseif ($_POST['sku'.$i] == "AOI0004")
			header('Location: http://www.sitename.com/hardcopythankyou.php');
	}
	else
		break;
}
}
?>

 

I thought that the problem would be on line 1, but there is nothing but the opening PHP bracket - no empty space or anything that could cause an issue.

 

Any thoughts on a cause for the problem?

Did you save the file as UTF-8?  If so, there could be a byte order mark (BOM) that you can't see at the beginning of the file.  Some editors have the option to turn it off, so look.  If not, open a hex editor and find it.

Did you save the file as UTF-8?  If so, there could be a byte order mark (BOM) that you can't see at the beginning of the file.  Some editors have the option to turn it off, so look.  If not, open a hex editor and find it.

 

Dreamweaver has the option to include a BOM - I unchecked it, still no go.

 

Or if you've included the file from another, make sure you haven't already outputted anything ;)

 

Not included anywhere - I just present this page, nothing else.

 

Thanks for your replies, though!

NOTEPAD++ ftw :]

Oh, and make sure there isn't a cheeky little space before the <?php :P

 

----------------

Now playing: Linkin Park - The Little Things Give You Away (Live At Milton Keynes)

via FoxyTunes

Here's what you can do.  Open Notepad (regular ol' Notepad) and just copy and paste your code in:

<?php session_start();
if (isset($_POST))
{
if ($_GET['us'] != 'true')
{	
	foreach ($_POST as $key => $value)
		$_SESSION[$key] = $value;

}

for ($i=1;$i<20;$i++)
{
	if(isset($_POST['sku'.$i]))
	{
		if ($_POST['sku'.$i] == "AOI0000")
			header('Location: http://www.sitename.com/bookthankyou.php');
		elseif ($_POST['sku'.$i] == "AOI0004")
			header('Location: http://www.sitename.com/hardcopythankyou.php');
	}
	else
		break;
}
}
?>

 

And save it.  Try that.  Just copy and paste it from here.

Eww, you use Dreamweaver?  Anyway....try going into a hex editor and manually deleting it.  I suggest XVI32 as your hex editor. =P

 

Tried XVI32, removed three small symbols from the start, and it works! Thanks!

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.