开发者

Problem while changing CSS using php

开发者 https://www.devze.com 2023-03-03 11:41 出处:网络
I am trying to change my css file using php, so in order to do so, I changed my default.css into default.php and put a <?php header(\"Content-type: text/css\"); ?> in the top, then using a form

I am trying to change my css file using php, so in order to do so, I changed my default.css into default.php and put a <?php header("Content-type: text/css"); ?> in the top, then using a form I take input from the user and change the css using ph开发者_运维问答p. I could successfully done it, but problem is it's showing the following error, which I cant figure it out why?

fyi: in the index page <link rel="stylesheet" type="text/css" href="default.php"> I put this to make sure, that index page still get its stylesheet.php

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\asterisk\default.php:2) in C:\xampp\htdocs\asterisk\default.php on line 2


If you're setting headers make sure that you call the header() function at the top of the page, or at least do some ob_flush() before headers are sent if text must be on the page.


The error says it all: You use header after sending content to the client. You must make sure, that header is called before any content is sent. Look for header('Content-Type: text/css') or something like that. It must be used before any inline CSS and before any print or echo statements.


That error is common when you echo or print something, before calling a header command.


so in default.php at line 2 it start output. Set up header before this ... and all b Ok .


Reason : Warning: Cannot modify header information error comes when some output already has been sent to the browser before calling of header()

Solution: use ob_start() at the top of the page just after <?php
Best Practice : also use exit() just after header()

REFERENCE

0

精彩评论

暂无评论...
验证码 换一张
取 消