canu
asked on
PHP Error - Urgent
Hi,
I have taken over the administration of a website which has one PHP webpage that unfortunately has an error on it, this URL is as follows: http://www.paradiseboats.com/v3/contact.php
The error messages are as follows:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/95/98/1009895/web/v3 /contact.p hp:1) in /home/95/98/1009895/web/v3 /contact.p hp on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/95/98/1009895/web/v3 /contact.p hp:1) in /home/95/98/1009895/web/v3 /contact.p hp on line 2
I don't know PHP but am happy to roll up my sleeves if I receive simple instructions.
Does anyone have any ideas what the problem is and how I can go about fixing it?
Any help would be much appreciated.
Thanks!
I have taken over the administration of a website which has one PHP webpage that unfortunately has an error on it, this URL is as follows: http://www.paradiseboats.com/v3/contact.php
The error messages are as follows:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/95/98/1009895/web/v3
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/95/98/1009895/web/v3
I don't know PHP but am happy to roll up my sleeves if I receive simple instructions.
Does anyone have any ideas what the problem is and how I can go about fixing it?
Any help would be much appreciated.
Thanks!
I agree with gr8gonzo. Make sure you are using a code editor like Notepad++ that will not add formatting commands to your PHP files.
The space could be at the beginning or the end of an included file
Sometimes you get this
include 'somefile.php';
...
And in somefile.php you have
Otherwise, go into all php files referenced by your landing page - and the files they reference and make sure there is no white space outside of the <?php ?> tags
Sometimes you get this
include 'somefile.php';
...
And in somefile.php you have
<?php
// code
?>
[A Space here]
A good practice is to not close opening php tags in files that are pure script in other words<?php
// code
// no closing tag
This ensures that any spaces at the end of the file are interpreted as script not output and so you don't get the problem.Otherwise, go into all php files referenced by your landing page - and the files they reference and make sure there is no white space outside of the <?php ?> tags
ASKER
Hi both, thanks for the quick response and there wasn't a blank ahead of the first "<?".
I changed the number of characters for the unique string and also blanked out the section to do with the captcha generator at the end of the page.
Here's the rest of the code :
I changed the number of characters for the unique string and also blanked out the section to do with the captcha generator at the end of the page.
Here's the rest of the code :
<?php
session_start();
// You need a unique string that identifies the user. The easiest way is to
// simply use the session ID. But because sending session IDs to other servers
// can be a security problem, we use only a part of the session ID here.
// This is still a quasi-unique string, so it works just as well.
$captcha_id = substr(session_id(), 0, Z); // first Z characters of the session ID
?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paradise Boats</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_showHideLayers() { //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body style="text-align:center;" onload="MM_preloadImages('images/navigation/homedn.jpg','images/navigation/boatsdn.jpg','images/navigation/rentalsdn.jpg','images/navigation/productsdn.jpg','images/navigation/contactdn.jpg','images/navigation/linksdn.jpg')">
<div style="width:1000px; height:640px; text-align:center; margin:0 auto;"><div>
<img src="images/headerlogo.jpg" width="1000" height="139" /></div>
<div style="height:24px;"> <a href="index.html">
<img src="images/navigation/homeup.jpg" alt="Home" name="home" border="0" id="home" onmouseover="MM_swapImage('home','','images/navigation/homedn.jpg',1); MM_showHideLayers('salesdrop','','hide'); MM_showHideLayers('rentalsdrop','','hide');" onmouseout="MM_swapImgRestore()" width="88" height="24" /></a><a href="boats.html"><img src="images/navigation/boatsup.jpg" alt="Boats" name="boats" border="0" id="boats" onmouseover="MM_swapImage('boats','','images/navigation/boatsdn.jpg',1); MM_showHideLayers('salesdrop','','show'); MM_showHideLayers('rentalsdrop','','hide');" onmouseout="MM_swapImgRestore()" width="143" height="24" /></a><a href="rentals.html"><img src="images/navigation/rentalsup.jpg" alt="Rentals" name="rentals" border="0" id="rentals" onmouseover="MM_swapImage('rentals','','images/navigation/rentalsdn.jpg',1); MM_showHideLayers('rentalsdrop','','show'); MM_showHideLayers('salesdrop','','hide');" onmouseout="MM_swapImgRestore()" width="197" height="24" /></a><a href="products.html"><img src="images/navigation/productsup.jpg" alt="Products" name="products" border="0" id="products" onmouseover="MM_swapImage('products','','images/navigation/productsdn.jpg',1); MM_showHideLayers('salesdrop','','hide'); MM_showHideLayers('rentalsdrop','','hide');" onmouseout="MM_swapImgRestore()" width="187" height="24" /></a><a href="contact.php"><img src="images/navigation/contactup.jpg" alt="Contact" name="contact" border="0" id="contact" onmouseover="MM_swapImage('contact','','images/navigation/contactdn.jpg',1); MM_showHideLayers('rentalsdrop','','hide');" onmouseout="MM_swapImgRestore()" width="112" height="24" /></a><a href="links.html"><img src="images/navigation/linksup.jpg" alt="Links" name="links" border="0" id="links" onmouseover="MM_swapImage('links','','images/navigation/linksdn.jpg',1); MM_showHideLayers('rentalsdrop','','hide');" onmouseout="MM_swapImgRestore()" width="76" height="24" /></a><img src="images/navigation/navigationbg.jpg" width="197" height="24" /><div style="position:relative; visibility:hidden; border:0px; z-index:800;" id="salesdrop">
<div style="position:absolute; left: 85px; top: 0px;" onmouseover="MM_showHideLayers('salesdrop','','show')" onmouseout="MM_showHideLayers('salesdrop','','hide');">
<table border="0" align="center" cellpadding="0" cellspacing="0" style="background: #4BA948; border-collapse:collapse;" >
<tr><td style="padding-top: 10px; padding-right: 12px; padding-bottom: 5px; padding-left:15px;" align="left"><a href="boats.html" class="navlink"> NEW BOATS </a></td></tr><tr><td style="padding-top: 5px; padding-right: 12px; padding-bottom: 5px; padding-left:15px;" align="left"><a href="http://www.yachtworld.com/paradiseboatsales/index.html" target="_blank" class="navlink"> PRE-OWNED BOATS </a></td></tr><tr><td style="padding-top: 5px; padding-right: 12px; padding-bottom: 10px; padding-left:15px;" align="left"><a href="http://www.rockettrailers.com" target="_blank" class="navlink"> BOAT TRAILERS </a></td></tr></table></div></div><div style="position:relative; visibility:hidden; border:0px; z-index:800;" id="rentalsdrop">
<div style="position:absolute; left: 235px; top: 0px;" onmouseover="MM_showHideLayers('rentalsdrop','','show')" onmouseout="MM_showHideLayers('rentalsdrop','','hide');">
<table border="0" align="center" cellpadding="0" cellspacing="0" style="background: #4BA948; border-collapse:collapse;" >
<tr><td style="padding-top: 10px; padding-right: 12px; padding-bottom: 5px; padding-left:15px;" align="left"><a href="boatrentals.html" class="navlink"> BOAT RENTALS </a></td></tr><tr><td style="padding-top: 5px; padding-right: 12px; padding-bottom: 5px; padding-left:15px;" align="left"><a href="boatcharters.html" class="navlink"> BOAT CHARTERS </a></td></tr><tr><td style="padding-top: 5px; padding-right: 12px; padding-bottom: 5px; padding-left:15px;" align="left"><a href="cyclerentals.html" class="navlink"> CYCLE RENTALS </a></td></tr><tr><td style="padding-top: 5px; padding-right: 12px; padding-bottom: 10px; padding-left:15px;" align="left"><a href="sales.html" class="navlink"> AUTO LEASING/SALES </a></td></tr></table></div></div></div>
<div style="height:10px;"><img src="images/headerbottom.jpg" width="1000" height="10" /></div>
<div><table width="100%" height="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" background="images/contentbg.jpg" width="700" valign="top" style="padding: 10px;"><div>
<p><img src="images/pages/common/Animation5.gif" width="696" height="291" /></p>
<p align="left">At Paradise Boat Sales in Antigua we have a huge selection
of new boats ……………… <br>
We also offer boat management, brokerage, rentals and charters and
re-powering</p>
</div>
<?php
if (!isset($_POST[Submit])) {
?>
<div><form name="contact" method="post" action="contact.php" enctype="multipart/form-data">
<table border="0" cellpadding="0" cellspacing="3" style="border-collapse: collapse" bordercolor="#111111" width="650">
<tr>
<td align="left" valign="top">
<table width="90%" border="0">
<tr>
<td width="35%" align="right" class="style7"><span class="style8"> I would like to: </span></td>
<td width="65%"><select name="select" id="select">
<option selected>Select One</option>
<option>Rent a Boat</option>
<option>Charter a Boat</option>
<option>Charter Other</option>
<option>Buy New Boat</option>
<option>Buy Used Boat </option>
<option>Order Services</option>
<option>Request Information</option>
<option>Other</option>
</select> </td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8"> Name:</span></td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td align="right" class="style9">Address:</td>
<td><textarea name="address" id="address" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td align="right" class="style9">City:</td>
<td><input name="city" type="text" id="city" size="30"></td>
</tr>
<tr>
<td align="right" class="style9">State:</td>
<td><strong>
<input type="text" name="state" size="30">
</strong></td>
</tr>
<tr>
<td align="right" class="style9">Zip:</td>
<td><strong>
<input type="text" name="zip" size="15" id="zip">
</strong></td>
</tr>
<tr>
<td align="right" class="style9">Country:</td>
<td><strong>
<input type="text" name="country" size="30">
</strong></td>
</tr>
<tr>
<td align="right" class="style9">Phone:</td>
<td><strong>
<input type="text" name="phone" size="30">
</strong></td>
</tr>
<tr>
<td align="right" class="style9">Fax:</td>
<td><strong>
<input type="text" name="fax" size="30">
</strong></td>
</tr>
<tr>
<td align="right" class="style9">E-mail:</td>
<td><strong>
<input type="text" name="email" size="40">
</strong></td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8">How may we
assist you?</span></td>
<td><strong>
<textarea rows="3" name="cruise" cols="40"></textarea>
</strong></td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8"> Would you like to receive a brochure</span></td>
<td><strong>
<select size="1" name="brochure">
<option>Yes</option>
<option>No</option>
</select>
</strong></td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8"> Would you like information about a specific Boat or Engine Model?</span></td>
<td> <strong>
<select size="1" name="boat_information">
<option>Yes</option>
<option>No</option>
</select>
</strong></td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8">Are you
planning to buy or rent a boat in the next:</span></td>
<td> <strong>
<select size="1" name="plantobuy">
<option selected>3 Months</option>
<option>6 Months</option>
<option>One Year</option>
<option>Two Years</option>
</select>
</strong></td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8"> Do you want a representative to contact you?</span></td>
<td> <strong>
<select size="1" name="representative_contact">
<option>Yes</option>
<option>No</option>
</select>
</strong></td>
</tr>
<tr>
<td align="right" class="style7"><span class="style8"> Comments or Questions</span></td>
<td><strong>
<textarea rows="5" name="comments" cols="40"></textarea>
</strong></td>
</tr>
<tr>
<td>Security Code:</td>
<td><img src='http://captchator.com/captcha/image/<?php echo $captcha_id; ?>'/><br /><input type='text' name='captcha' size='Z'></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" id="Submit" value="Submit">
<input type="reset" name="Reset" id="Reset" value="Reset"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</td>
<td align="left" valign="top" width="170">CONTACT DETAILS<br>
<br>
Phone: (268) 463 - 7125<br>
Phone: (268) 462 - 5760<br>
Fax: (268) 562 - 9651<br>
Cell: (268) 764 - 7766<br>
Email:
<a href="mailto:paradise@candw.ag?subject=Contact from www.paradiseboats.com">paradise@candw.ag</a></td>
</tr>
</table>
</form>
<p align="left"> </p>
</div>
<?php
}
else {
/*********************REGISTER******************************/
}
?></td>
<td bgcolor="#FFFFFF" valign="top" width="280" height="600"><iframe src="rightside.html" width="280" height="1000" scrolling="no" frameborder="0"></iframe></td>
</tr>
</table>
</div>
<div style="height:80px;"><img src="images/footerbg.jpg" width="1000" height="80" /></div>
</div>
</body>
</html>
Assuming the error message isn't lying then there are 2 possibilities:
1. You're looking at the wrong file. (It happens)
...OR...
2. There are some invisible characters that are before the <?php. If you've encoded the file as UTF-8, sometimes editors will throw a couple of bytes at the beginning called a Byte Order Mark or BOM for short. These bytes won't actually show up in many editors because they are just "instructional" in nature, but they are technically considered to be output.
As someone else mentioned, Notepad++ is a good, free editor that has an Encoding option to convert/encode and save files as UTF-8 without the BOM.
Optionally, if all you have to work with is the regular Notepad, then just make sure you save it with ANSI encoding. That should strip out any BOM at the beginning, too.
1. You're looking at the wrong file. (It happens)
...OR...
2. There are some invisible characters that are before the <?php. If you've encoded the file as UTF-8, sometimes editors will throw a couple of bytes at the beginning called a Byte Order Mark or BOM for short. These bytes won't actually show up in many editors because they are just "instructional" in nature, but they are technically considered to be output.
As someone else mentioned, Notepad++ is a good, free editor that has an Encoding option to convert/encode and save files as UTF-8 without the BOM.
Optionally, if all you have to work with is the regular Notepad, then just make sure you save it with ANSI encoding. That should strip out any BOM at the beginning, too.
https://www.experts-exchange.com/articles/4423/Warning-Cannot-modify-header-information-headers-already-sent.html
Be aware of the difference between Notepad++ and Notepad. These are not the same and Notepad may inject BOM into your files!
Be aware of the difference between Notepad++ and Notepad. These are not the same and Notepad may inject BOM into your files!
The answer is in the error message
(output started at /home/95/98/1009895/web/v3 /contact.p hp:1
It is saying the output was started on line 1 of contact.php. Was that contact.php that you posted?
If you attach the file instead of posting we should be able to see if there are any "invisible" characters at the start.
(output started at /home/95/98/1009895/web/v3
It is saying the output was started on line 1 of contact.php. Was that contact.php that you posted?
If you attach the file instead of posting we should be able to see if there are any "invisible" characters at the start.
ASKER
Hi All,
I sent the code for this PHP file, I will attach a slightly amended version of the contact.php file.
Any more comments would be welcomed.
contact.php.txt
I sent the code for this PHP file, I will attach a slightly amended version of the contact.php file.
Any more comments would be welcomed.
contact.php.txt
That file does not generate any errors here
ASKER
Thanks Julian.
Can I ask you to take a look at the page by clicking the following link: http://www.paradiseboats.c om/v3/cont act.php
I've attached a screenshot of what I see at my end.
paradise-boats-screenshot.jpg
Can I ask you to take a look at the page by clicking the following link: http://www.paradiseboats.c
I've attached a screenshot of what I see at my end.
paradise-boats-screenshot.jpg
I have already seen that page - there is an error showing which tells me either the file you posted is not the same file behind the page.
I noticed that in the code you posted there is the following on line 238 there is the following (illegal) line
You can either post the full file here or
1. Cut and paste the content out of your existing file - take the content from below the <?php and paste it into a completely new file
2. Rename the old contact.php and save the new one as contact.php
Try that and report back.
I noticed that in the code you posted there is the following on line 238 there is the following (illegal) line
if (implode(file("http://captchator.com/captcha/check_answer/".$captcha_id."/".$answer)) == '1') {FORM SCRIPT HERE}
This suggests that the file you uploaded is probably not the same as the one you are running on disk.You can either post the full file here or
1. Cut and paste the content out of your existing file - take the content from below the <?php and paste it into a completely new file
2. Rename the old contact.php and save the new one as contact.php
Try that and report back.
ASKER
Hello Julian,
The line that you noticed was illegal contains the form script that I'm not comfortable divulging on this public forum so I replaced it with the text 'FORM SCRIPT HERE'.
I would be happy to send the unamended code privately.
The line that you noticed was illegal contains the form script that I'm not comfortable divulging on this public forum so I replaced it with the text 'FORM SCRIPT HERE'.
I would be happy to send the unamended code privately.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Now that we know that @gr8gonzo's comment right at the top was the EXACT description of the problem, we can move forward. This is a UTF-8 artifact. We have an article here at E-E that identifies and explains the problem.
https://www.experts-exchange.com/articles/11880/Unicode-and-Character-Collisions.html
Best of luck with your project! ~Ray
https://www.experts-exchange.com/articles/11880/Unicode-and-Character-Collisions.html
Best of luck with your project! ~Ray
ASKER
Thanks so much for your patience gr8gonzo, I've (finally) taken your advice and the issue has been solved.
Next, this is USUALLY caused by some blank space at the top of PHP files. Try editing that contact.php file and going to the VERY top of it, at the very first character and make sure there are no blank lines or any spaces before the first instance of "<?"