Hi, I have been puzzling over this one for some time, maybe you can help. I have a web page, which starts with: <?php session_start(); ?><html code ...> Code (markup): But when I run the page I get these errors: It acts like it has been included from another file where the headers have already been sent, or something like that. I have tried copying the code exactly to another page, and it gets no error, so the code must be fine, right? Can anyone help?
The session_start() needs to before any HTML is sent to the browser, which I imagine includes white-space. Are there any new lines, spaces, tabs etc. before <?php?
Is there any white space or anything at all before your PHP code? That's the only way to my knowledge this error could be happening.
Here's the entire code: <?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>X-Byte Hosting</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen, projection" charset="utf-8" /><script type="text/javascript"> // <![CDATA[ function agreetest(){ (document.gog.gogo.disabled) = (document.gog.agree.checked) ? false : true; } 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; } // ]]> </script> <script language="javascript"> //Ajax check url var url = "ajax_callback.php?d="; function chk_me() { //Create Temporary message var notationS = document.getElementById("results") notationS.innerHTML = '<img src="please_wait.gif">'; //Check domain here var word_value = document.getElementById("domain").value var tld = document.getElementById("tld").value; http.open("GET", url + escape(word_value+"."+tld), true); http.onreadystatechange = handleHttpResponse; http.send(null); } function handleHttpResponse() { if (http.readyState == 4) { // Split the comma delimited response into an array var domain = document.getElementById("domain").value; var tld = document.getElementById("tld").value; var results = http.responseText; //If domain is valid if(results == '0'){ var is_show = '<font color="#0000FF">Invalid Domain '+domain+'.'+tld+' Name.</font>'; } else { if(results == '1'){ var is_show = '<font color="#0000FF">Domain Name '+domain+'.'+tld+' is available. <a href="order.php?page=domain&domain='+domain+'&tld='+tld+'">Order</a></font>'; } else { var is_show = '<font color="#FF0000">Domain Name '+domain+'.'+tld+' is taken.</font>'; } } var notationS = document.getElementById("results") notationS.innerHTML = is_show; } } function getHTTPObject() { var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } var http = getHTTPObject(); // We create the HTTP Object </script> <script type="text/javascript"> // <![CDATA[ function agreetest(){ (document.gog.gogo.disabled) = (document.gog.agree.checked) ? false : true; } 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_validateForm() { //v4.0 var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } // ]]> </script> <script src="scriptaculous/lib/prototype.js" type="text/javascript"></script> <script src="scriptaculous/src/effects.js" type="text/javascript"></script> <script type="text/javascript" src="fabtabulous.js"></script> <script type="text/javascript" src="validation.js"></script> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> </head> <body id="home"> <div id="siteNav"> <a href="http://x-bytehosting.co.uk/" title="X-Byte Hosting"><img src="images/logo.png" alt="X-Byte Hosting" width="144" height="59" border="0" /></a><ul> <li><a href="contact.php"> Contact </a></li> <li><a href="hosting.php"> Hosting </a></li> <li><a href="domains.php"> Domains </a></li> <li><a href="index.php">Home</a></li> </ul> <div class="clear"></div> </div> <div id="wrapper"> <div id="center"> <div id="banner"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','800','height','188','title','We know, hosting.','src','images/banner','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','images/banner' ); //end AC code </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="800" height="188" title="We know, hosting."> <param name="movie" value="images/banner.swf" /> <param name="quality" value="high" /> <embed src="images/banner.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="188"></embed> </object></noscript> </div> <div id="content"> <h3> </h3> <h3><span class="style1">Cart</span></h3> <p><br /> <?php include("cart.inc.php"); ?></p> <div class="clear"></div> </div> <div id="news"> <h5> </h5> <h5><a href="hosting.php">Gold Hosting </a></h5> <p>Unlimited web space<br /> Unlimited bandwidth <br /> Unlimited everything!!! </p> <h5><a href="hosting.php">Silver Hosting </a></h5> <p>10gb web space <br /> 100gb bandwidth <br /> 5000 email addresses</p> <h5><a href="hosting.php">Bronze Hosting </a></h5> <p>2gb web space <br /> 30gb bandwidth <br /> 1000 email addresses</p> <p>All these deals can be snapped up for an amazing price, if you want to order something, just start <a href="domains.php">here</a>! </p> <p> </p> </div> <div class="clear"></div> </div> </div> <div id="copyright"> <div class="line"><?php if(isset($_SESSION['domain']) && isset($_SESSION['hosting'])){ echo '<a href="cart.php">Shopping Cart</a> | '; }?><a href="status.php">Network Status</a> | <a href="terms.php">Terms and Conditions</a><br />© 2007 <a href="http://x-byte.co.uk/">X-Byte</a> <a href="http://x-bytehosting.co.uk/">Hosting</a> · Design by <a href="http://thispixel.net/">This Pixel</a></div> </div> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-1949947-1"; urchinTracker(); </script> </body> </html> Code (markup): But I don't think there can be anything wrong with the code because if I copy the code and paste it all into a new page, it works. The problem is that most of the pages in the site are based on a dreamweaver template, and the error seems to go with the template. I have tried detatching them from the template but it doesn't help.
I can't see anything wrong with what you've got there - normally what I would assume is that your host has some special setting where they output something of their own before your code (like Geocities, Tripod, Hypermart did back in the good ol' early days of the net), but as you're offering a hosting service yourself I don't image that is it. Have you changed any settings in php.ini that you're not certain of what they do? I don't know specifically of any that would cause this, but that's the only place I can think of to look.
We are offering a hosting service, but we use a reseller package from another host, rather than have our own servers, and I did think of that as a possibility. However, I have tried the script on my computer, at localhost, and it generates the same error. I haven't changed any php.ini settings that I don't know about, and the strange thing is that I can copy the code to another file and it works fine, but if I copy the file itself it still generates the error. This makes me think there is something in the meta of the file, or the permissions maybe, but I have checked the permissions, and they are fine, so I can't think of anything else.
Do you use any caching system (for example zend). I had a similar problem, you should try to overwrite the page with a new page, reload it in the browser, and then paste the old code in the page again.
Well I don't use zend, I do use dreamweaver. Overwriting it does work, but it will take a long time to do, and it kind of destroys the point of using a template, but it's all I can do. Thanks