timmah1 Posted July 19, 2009 Share Posted July 19, 2009 I know there is a sticky about this. This is the top of my page, nothing is being passed except the setcookie() at the very top, unless you count the <?php Why am I constantly getting a header already sent out error? <?php setcookie('aff_ses', session_start()); setcookie('aff_id', $_GET['aff_id']); setcookie('aff_ip', $_SERVER['REMOTE_ADDR']); setcookie('aff_ref', $_SERVER['HTTP_REFERER']); setcookie('longtime', 'nextyear', time() + (60 * 60 * 24 * 365)); $nextYear = time() + (60 * 60 * 24 * 365); setcookie('visittime', time(), $nextYear); $referer = preg_replace("/(http:\/\/(.*)\/)[\S]*/", "\\1", $_SERVER['HTTP_REFERER']); $name = preg_replace("/http:\/\//", "", $referer); require("config2.php"); $query = "SELECT * FROM affiliates_session WHERE aff_ses = '".session_id()."' AND aff_id ='". $_COOKIE['aff_id']."'"; $q = mysql_query($query); $numrows = mysql_num_rows($q); if($numrows == 0){ $sql = "INSERT INTO affiliates_session(aff_ses, aff_id, aff_ip, aff_ref, aff_bas) VALUES( '".session_id()."', '".$_COOKIE['aff_id']."', '".$_COOKIE['aff_ip']."', '".$_COOKIE['aff_ref']."', '".$name."');"; mysql_query($sql) or die("Sorry, there was a problem adding new sponsor<br /> ".mysql_error()); //$comment = "Info has been inserted<br />"; } else { //$comment = "No info inserted<br />"; } require("testVals.php"); $current = date("Y-m-d"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN""http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- Start Meta Data --> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Vegas Sports Picks - Free Sports Picks - Sports Betting Picks</title> <meta name="title" content="Vegas Sports Picks - Free Sports Picks "> <meta name="description" content="<?=$desc1;?>" /> <meta name="keywords" content="<?=$keywords;?>" /> <META name="robots" content="index,follow"> <meta name="verify-v1" content="nVIzcVVxXdW7adyPpAZ0CsuM4QV4s7Ag1kBL088lw/M=" > <link href="https://secure.vegasdsports.com/main.css" rel="stylesheet" type="text/css" /> Another thing, this is running on a secure (SSL) server, does that make a difference? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 19, 2009 Share Posted July 19, 2009 wouldn't this line set a cookie with either true or false on the clients machine, depending on wether or not the session started? setcookie('aff_ses', session_start()); Shouldn't you been saving the session id on the clients machine? session_start(); setcookie( 'aff_ses', session_id() ); Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 19, 2009 Author Share Posted July 19, 2009 I tried this session_start(); setcookie( 'aff_ses', session_id() ); But it still gives me the header already sent out error and I don't understand why Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 19, 2009 Share Posted July 19, 2009 does it say which line? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 19, 2009 Author Share Posted July 19, 2009 Here are the errors Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 3 Warning: Cannot modify header information - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 5 Warning: Cannot modify header information - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 6 Warning: Cannot modify header information - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 8 Warning: Cannot modify header information - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 11 Here is the code <?php session_start(); setcookie('aff_ses', session_id()); setcookie('aff_id', $_GET['aff_id']); setcookie('aff_ip', $_SERVER['REMOTE_ADDR']); setcookie('aff_ref', $_SERVER['HTTP_REFERER']); setcookie('longtime', 'nextyear', time() + (60 * 60 * 24 * 365)); $nextYear = time() + (60 * 60 * 24 * 365); setcookie('visittime', time(), $nextYear); $referer = preg_replace("/(http:\/\/(.*)\/)[\S]*/", "\\1", $_SERVER['HTTP_REFERER']); $name = preg_replace("/http:\/\//", "", $referer); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN""http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- Start Meta Data --> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Vegas Sports Picks - Free Sports Picks - Sports Betting Picks</title> <meta name="title" content="Vegas Sports Picks - Free Sports Picks "> <meta name="description" content="<?=$desc1;?>" /> <meta name="keywords" content="<?=$keywords;?>" /> <META name="robots" content="index,follow"> <link href="https://secure.vegasdsports.com/main.css" rel="stylesheet" type="text/css" /> It shouldn't matter whether this on a SSL or not right? Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 19, 2009 Share Posted July 19, 2009 I don't think the SSL should make a difference, The code seems to work fine for me in a little setup i just made... How about trying http://au.php.net/ob_start and http://au.php.net/manual/en/function.ob-end-flush.php Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2009 Share Posted July 19, 2009 If there are no actual characters on line 1 in the file before the <?php tag, that error means that you file has been saved as a Unicode/UTF-8 (or 16) encoded file and the BOM (Byte Order Mark) characters that your editor put at the start of the file are the output that is causing the headers to not work. Save your file as an ANSI/ASCII file or save it as a Unicode/UTF-8 without the BOM. P.S. Output buffering should not be used to solve content/header problems and in this case where the output is coming on line 1 of the file, it won't work anyway. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 19, 2009 Author Share Posted July 19, 2009 PFMaBiSmAd, I have been using DW for my pages forever, and have never ran into this problem before. I have always started a new PHP page, and saved it and everything works fine. How do I go about saving the page correctly? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2009 Share Posted July 19, 2009 In the "file save/as" dialog, there should be a choice for what encoding the file is saved as. If there is not a choice to save the file the way you want it, create a new file and copy/paste the contents of the existing file into the new one. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 19, 2009 Author Share Posted July 19, 2009 I don't see an encoding choice, anywhere, and when I create a new file and save it, the same issues happens I checked my preferences, and I see a box for Default Encoding, which is set to Unicode(UTF-, there is no option for ANSI/ASCII. Also, there is a drop down for Unicode Normalization Form with a checkbox that says Include Unicode Signature (BOM). The choices for the Normailization form are C (Canonical Decomposition, followed by Canonical Compostion) D (Canonical Decompostion) KC (Compatitbility Decomposition, followed by Canonical Compostion) KD (Compatitbility Decompostion) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2009 Share Posted July 19, 2009 Form with a checkbox that says Include Unicode Signature (BOM) How about un-check that checkbox. You can also use a real programming editor like Notepad++. It will let you save the file the way you want it to. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 19, 2009 Author Share Posted July 19, 2009 I took all that other stuff out, and am just using this now <?php session_start(); require("config.php"); ?> <!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>Vegas Sports Picks - Free Sports Picks - Sports Betting Picks</title> <meta name="title" content="Vegas Sports Picks - Free Sports Picks "> <meta name="description" content="<?=$desc1;?>" /> <meta name="keywords" content="<?=$keywords;?>" /> <META name="robots" content="index,follow"> <link href="https://secure.vegasdsports.com/main.css" rel="stylesheet" type="text/css" /> And I get this Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/vegas/public_html/core/index.php:1) in /home/vegas/public_html/core/index.php on line 2 I'm going nuts because has never happened before Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 19, 2009 Author Share Posted July 19, 2009 PFMaBiSmAd, I downloaded Notepad++, re-saved my page, and it works. Do you have any idea why that would all of a sudden start doing that in DW? Thank you for all your help Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2009 Share Posted July 19, 2009 DW was never intended to be used with server side scripting languages like PHP, so it does not know or care about code that would be sending headers and would require a way of saving a file without the BOM or saving it as ANSI. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.