This is my first question and I will try to do a good job.
I use a DSS file for my website in development as I want to "display:none" some divs if certain conditions are met (user is logged in -> no need for a register-form)
So my index.php head-tag for linking the stylesheet looks as follows:
<link rel="stylesheet" href="css/default.php" type="text/css">
the default.php CSS file has the following start:
<?php
session_start();
header('Content-type: text/css');?>
On my local webserver (xampp on OS X) everything works just fine.
But on the online server the css isn't applied. You can visit the broken website here:
hsturnierv2.pixelpioniere.net
It links the correct file, but the style is not applied.
EDIT:
Never underestimate the power of a linebreak.
The php-tag in the CSS file did not start at line 1. Thank you!
Your server is sending error message before the actual css:
http://hsturnierv2.pixelpioniere.net/css/default.php
Disable error displaying, or fix the issue with headers.
I go to your CSS link and get Warning:
Warning: session_start(): Cannot send session cache limiter - headers already sent
It means that your script file send the output for client before session_start().
Make sure there is absolutely no whitespace or another characters before <?php
If that fails, try commenting out the session_start() as one of your includes might already be starting the session, like so: /**session_start(); **/
Check the MIME type the server is returning your css with. https://developer.mozilla.org/en-US/docs/Incorrect_MIME_Type_for_CSS_Files
Note: Even though you wil get it to work the way you want, you should double-check if the reduction in CSS file size makes up for the impossibility to cache the CSS client-side.
Apart from that, the actual problem is that you try to modify header information when the header has already been sent. This puts error message output on top of your css, invalidating it.
<br />
<b>Warning</b>: session_start(): Cannot send session cache limiter - headers already sent (output started at /www/htdocs/w011c30e/hst/public_html/css/default.php:2) in <b>/www/htdocs/w011c30e/hst/public_html/css/default.php</b> on line <b>3</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /www/htdocs/w011c30e/hst/public_html/css/default.php:2) in <b>/www/htdocs/w011c30e/hst/public_html/css/default.php</b> on line <b>4</b><br />
You've inserted PHP code into your CSS file, that is wrong, please remove it.
<?php
session_start();
header('Content-type: text/css');?>
This is for your PHP file.
Related
I am having this error in PHP:
session_start(): Cannot send session cache limiter - headers already
sent
I know I have to put session_start() even before the html <head>, what I am doing. The issue here is that I am using id containers for ajax generated content.
For example, I have a button in the homepage.php which updates some calculate.php file in a divResults, and this calculate.php begins with session_start(). However, this warning is appearing inside divResults.
How could I solve it. Is it possible to simply ignore the warning. How?
(I don't have this problem in XAMPP, only using an external hosting provider)
Thanks
Based on your problem following errors may possible.
you write session_start(); in somewhere middle or end of the .php file so you need to put session_start();at top of .php file just after <?php.
May be some empty lines are there in your .php file at the beginning or end, because of that also this error will arise. remove those empty line.
I have written the below script (snipped) that includes the WordPress functions, however it appears one of the plugins is trying to start a session when it has already been started:
<?php
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
...
?>
I get the following in my php errors log:
<b>Warning</b>: session_start(): Cannot send session cookie - headers already sent in <b>/home/sp32/public_html/wp-content/plugins/woocommerce-abandon-cart-pro/woocommerce-ac.php</b> on line <b>44</b><br />
<br />
<b>Warning</b>: session_start(): Cannot send session cache limiter - headers already sent in <b>/home/sp32/public_html/wp-content/plugins/woocommerce-abandon-cart-pro/woocommerce-ac.php</b> on line <b>44</b><br />
I'm assuming this is an error in the plugin itself, however I want to prevent these warnings from showing in my log file for my specific script. How would I go about that? Ideally I don't want to hide all warnings, just this one.
Note that is not a duplicate- I am not asking how to fix the issue (because the issue lies in a 3rd party plugin), I am asking how to suppress the warning messages.
There are three options I see here:
Fix the offending code. As you have mentioned, this may not be optimal with 3rd party code.
Ask for a refund, and replace this plugin with something well written; specifically, something that abides by an accepted coding standard such as PSR-2, or pear.
Find where the offending files are included (or offending functions are called and wrap them in calls to change the error reporting level (code below). The downside to this is that your sessions will not work, since the headers have already been sent by the plugin; this prevents a session cookie from being set, making the browser unrecognized by php sessions.
$previousErrorLevel = error_reporting();
error_reporting(\E_ERROR);
//offending code inclusion or call here
error_reporting($previousErrorLevel);
I am currently getting the following error using php:
Warning: session_start() [function.session-start]:
Cannot send session cache limiter - headers already sent
(output started at /home/paramireze/madisonh3.com/calendar.php:1)
in /home/paramireze/madisonh3.com/includes/common.php on line 5
The first line of every file is include common.php, and the first line of code in common.php is 'if(!isset($_SESSION)) {session_start();}`.
This error only occurs on calendar.php and news.php (you can see the error if you visit http://www.madisonh3.com/calendar.php). All my files are the same, which includes a common.php. After that, I will write the html tag and include the header from there.
I've read other discussions regarding session_start and all say to make sure you do not output any html before session_start. Also, if I am doing something wrong, why is it only happening to two out of my 10 files?
There is something outputting data BEFORE your session_start() command. As the session cookie is set to the HTTP header it must precede any HTML output.
The error Cannot send session cookie - headers already sent by (output started at /home/paramireze/madisonh3.com/calendar.php:1) in /home/paramireze/madisonh3.com/includes/common.php on line 5 indicates something is outputted before.
So look into your code and find what could be echoing data before your session_start().
You should care that your editor does not store the utf-8 BOM header, this header is sometimes stored at the begin of the file with 3 bytes .
The editor will hide them, so if you are not sure if your file contains these characters, you can either use a non interpreting editor (hex editor), or this wonderful online W3C checker. The BOM header is treated as output by PHP, and this can cause nasty Cannot modify header information - headers already sent errors.
Checking your URL shows, that there is indeed such a BOM header. Have a look at the settings of your editor (IDE).
My Site is not opening in IE. I know about CSS incompatibilities this is why I added the following code to redirect to a static page if UserAgent belongs to Internet Explorer. The code that detects IE and redirects is given below:
Site link is:
http://adnansiddiqi.com/main.html
http://pastebin.com/MCRbsrmi
The header file is included on top of the main.php
Please guide!
Now that you've got the site working properly, we finally have an error message:
Warning: Cannot modify header information - headers already sent by (output started at /home/adnansid/public_html/main.php:10) in /home/adnansid/public_html/header.php on line 15
See item 6 from the list below. Don't call header() after you've already sent output. You must call it before any and all output.
Here are a series of things you need to fix/address/attempt:
Two undefined variables, isMobileSafari, and isOldMobileSafari.
Your <title> needs to be within your <head>.
No doctype was provided.
You're not outputting anything after the opening <body> tag.
Check to make sure you have short-tags enabled (try using the longform <?php ... ?>)
Don't call header() after you've already output content.
Check your log files for any obvious messages.
I tried accessing the same page in Chrome, thinking maybe you had broken your user-agent sniffing code, but I found that within Chrome as well nothing is output after the opening <body> tag.
I would try to diagnose the reason why your body isn't being output, but you've not provided enough code for us to do that. Please provide us a bit more to further assist you.
The quick solution is to avoid user-agent sniffing code, and instead detect features.
i think a JavaScript error is thrown
da1a2063-40eb-4efd-ae4b-c50a8eea8067.js, line 7 character 117
may be this script does not support IE , Did you use any API ? .. may be a workaround or a fix is available
I am currently working on a game in PHP and jQuery and at some point I will need to use the .load() from jQuery to load a PHP page into a div. That page will load some player information based on their login information, account id, etcetera, stored into an array inside $_SESSION["arrayname"].
It works perfectly on all sites, except those where jQuery load() is use. On easyphp, I got no errors, but on my web host server im getting this:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /fr/game/map.php:1) in fr/game/map.php on line 6
Here is my code:
<?php
require_once("../../connectionRO.inc.php");
//used to check if we see the array in session, and i dont when i load it with jquery
if(!ISSET($_SESSION["comptejeu"]))
{
require_once('../../classInfoCompte.php');
session_start();
require_once('../../lg.php');
require_once("./glg.php");
}
$ic = new infoCompte;
$ic = $_SESSION["comptejeu"];
?>
I understand that at this point a lot of stuff is already output to the page before that is loaded. Could anyone point me to a better way to retrieve the information that I need from that array to build my object from my class?
Thank you.
Since you are getting this error as output started at /fr/game/map.php:1 (note: line 1) I will place money on you having whitespace or a BOM before the opening <?php tag in /fr/game/map.php.
Make sure the opening < is the first character in the file. If you file is UTF-8, make sure it is UTF-8 without BOM, or convert it to ASCII.
Wrong:
<?php
Right:
<?php
Either there is some white space in your PHP file, there is some whitespace in classInfoCompute.php or there is a function/method call that triggers output in either this or the classInfoCompute file. Sessions depend on cookies, and cookies depend on HTTP headers. Once content has been output, the headers are already sent and you can't send a new one.
There are plenty of questions and answers on Stack Overflow that cover this issue, but it boils down to either sweeping the problem under the carpet (with output buffering), or fixing it properly (by finding what's causing content to be output before your call to session_start and either removing it or moving it to later in the script, or moving session_start to earlier in the script).
If your script mixes HTML and PHP then make sure that the session_start occurs before the first bit of HTML. Otherwise, you'll have to hunt around for white space. If the file is saved as UTF-8 then your text editor might have attached an unnecessary Byte Order Mark (BOM) to the start of the file. Make sure that your file is being saved without a BOM, because it will be treated as content and trigger output to the client (and put a weird character at the start of the output).