essjay_d12 Posted May 18, 2007 Share Posted May 18, 2007 I get the following error when im trying to set a cookie... Warning: Cannot modify header information - headers already sent by (output started at /srv/www/htdocs/testmoodle/theme/pcol/header.html:2) in /srv/www/htdocs/testmoodle/mod/resource/type/file/file.html on line 17 with the following code... <?php session_start(); // function to get current URL function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = curPageURL(); setcookie("URL", $url); ?> I need the result of that function in a cookie, but constantly giving me this error... why? cheers d Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/ Share on other sites More sharing options...
Bramme Posted May 18, 2007 Share Posted May 18, 2007 add ob_start(); to the very first line of your page (within <?php ?> tags offcourse) and ob_end_flush(); to your last line... that should solve it. Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/#findComment-256172 Share on other sites More sharing options...
MadTechie Posted May 18, 2007 Share Posted May 18, 2007 the problem is also related to header.html, can you post that (in code tags), or atleast the first 5 lines Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/#findComment-256204 Share on other sites More sharing options...
essjay_d12 Posted May 18, 2007 Author Share Posted May 18, 2007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html<?php echo $direction ?>> <head> <?php echo $meta ?> <link rel="stylesheet" type="text/css" href="<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/print.css" media="print" /> <meta name="keywords" content="moodle, <?php echo $title ?> " /> <title><?php echo $title ?></title> <link rel="shortcut icon" href="<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/favicon.ico" /> <?php include("$CFG->javascript"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/#findComment-256237 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 Well theirs your problem them your printing to the screen.. you should read the pinned posts first! Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/#findComment-256862 Share on other sites More sharing options...
essjay_d12 Posted May 21, 2007 Author Share Posted May 21, 2007 what you mean printing them to the screen? Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/#findComment-258092 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 outputting to the page.. ie <head> <body> or even <?php echo "Hello"; ?> please read the headers pinned post Quote Link to comment https://forums.phpfreaks.com/topic/51966-cookie-error/#findComment-258093 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.