I'm using AMP with PHP and when I'm trying the AMP validator (ttps://validator.ampproject.org/) I get a couple of errors that do not make sense become of a BOM character at the beginning of my page.
Example:
URL: https://www.laurentwillen.be/gadgets/xiaomi-redmi-note-7-test-avis-et-prix/
I get the following error: (among others)
The mandatory attribute '⚡' is missing in tag 'html'
If you look at the source of this page, the attribute is there but when you use the AMP validator, there is a red dot appearing at the very beginning of my page.
If I add a letter at the very top of my code like this:
A
<?PHP
// my code goes here
?>
I see the red dot appearing before the letter which highlights that my code is not generating the issue. In Notepad++ I see that the encoding is set to UTF8.
Do you know how I could remove this so that I can work on the real AMP errors?
Thanks
Laurent
I am getting an error which is very common.
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/sabarspinmatic/public_html/testing/index.php:1) in /home/sabarspinmatic/public_html/testing/index.php on line 1
But the strange this is I have only one php file with only 1 line of session_start().
PHP Code is:
<? session_start() ?>
Could anyone know why I am getting this error. I checked the source code and its showing <br />. I don't know why its showing this tag.
URL to check the error is: http://www.sabarspinmatic.com/testing/
//PART 2
I am just using single file index.php without use of .htaccess and only l line of code. I tried by putting php at start of tag but it doesn't work.
First, I would suggest you to use proper starting tag <?php, just in sake of code readability and portability - not all web servers are configured to support the shorter version <?.
Then make sure there is not even a whitespace before the <?php session_start() .... Also some editors (like Windows Notepad) tend to insert some invisible garbage at the very beginning of the file - so I suggest you to open the file in a HEXADECIMAL mode to see if there are really no characters before the <?php .... There could be for example the invisible UTF-8 BOM character.
Last, but not least, use a semicolon ; at the end of the command - no matter it is the only command in the code block, it is simply a best practice.
There me 2 reasons for the ocurrance of the above issue.
1) May in the including files session_start() is already written.
2) May be u are using the session_start() tag in middle of the code.It should be written in the first line of page.
Firstly short tags have been deprecated by php
use
<?php ?>
everywhere instead of
<? ?>
Also is this your entire page? Do you have a space or a line before very first text in the file
From my experience,removing all spaces in your code solves the problem.Especially if you have a white space before
This will cause the error:
..whitespace..<?php
Removing the whitespace solves the problem
I had the same problem... It was because of the Byte Order Mark (BOM) EFBBBF at the start of the file. Use any hex editor to remove these chars from the file and it should work.
I am getting 8 lines inserted at the beginning of each page in codeigniter framework, is it something with the framework and how do i remove these lines. I have tried to use hooks to minify html but i cant seem to remove the new lines inserted.
Found the answer from How do you remove a leading newline in output to browser in Codeigniter. The issue was new lines after php closing tag "?>" in one of my modules.
I've been struggling with this problem for a long time now, but I cannot really find the solution. The problem is that < !DOCTYPE html etc... does not start at the first line, but leaves four blank lines before it starts.
All my files (header.php, index.php etc) have no line breaks before they start.
Anyone with any similar problems/experiences out there? It would have been of huge help!
See here for reference: view-source:http://2famous.tv/
Thank you
This is most often not caused by leading but by trailing whitespace. Lots of old PHP code still closes down code at the end, which then all too often has a stray newline:
<?php
// Lot of source code
?> <----- and a newline here which is the culprit!
To avoid this issue, never close files with ?> - PHP doesn't need it and will just stop parsing at EOF, thus implicitly avoid this 'garbage' in the output.
As for finding the files causing it - good luck, I'd start with combing any custom extensions for this and just removing all ?> markers that you can find.
As an alternative, you can probably 'fix' it by adding a single ob_start() call to your index.php, and then in the template containing the doctype executing ob_end_clean() - this puts all intermediate output in the output buffers, and then trashes it.
I got some strange problem where i have 2 copies of same website in 2 different folders. In one of those 2 copies has whitespace before doctype declaration so i have problems to work with facebook as document is formated incorrectly.
Before html there is some php calculations, but there is no echo statements or something.
What could be cause for 2 identique websites under same server in different folders, one having this issue?
I'm almost positively certain that you have some trailing whitespace at the end of a PHP include. Check there first.
Example:
<?php
// header file
include 'other_file.php';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- etc. -->
Then
<?php
// other_file.php
// connects to database, or something,
// but notice the whitespace after the closing tag
?>
... pretend this text isn't here
I added the note at the end to get stackoverflow's markdown editor to show the additional lines after the closing ?> tag. PHP automatically truncates one newline character after the tag in includes, but if you have more than one they will be interpreted as blank space before your doctype declaration.
Easiest fix? Remove the closing tag ?> from all of your includes. This is a valid technique, and could be the fastest way for you to get up and running.
You don't say which browser you're having problems with. IE used to check the first few letters of the page for a doctype and, if it isn't one (such as whitespace), it would go into quirks mode.
This is especially common if you are using includes. Check over all your includes or other php files carefully that come before your output or headers.
<?
echo "php here";
?>
This will cause a problem if it's in an includes
that comes before your headers or doctypes.
Remove any non php here, file should end with "?>"
not whitespace, linefeeds or characters.
As for why? Unknown, on one production server this issue raises it's head constantly for me (CentOs 5) but on my dev machine (latest Fedora) it doesn't happen and I have no issues.
Honestly there's probably something I could track down to find out why, but since proper usage says "no extra spaces or lines" I just do that and don't worry too much about the "why is it handled differently on my servers" all that much. (Kind of a cop-out I know)
I ran into this where a line break was above the Doctype. I tried a few things and then ended up just placing the doctype in the php.
<?php
echo '<!DOCTYPE html>';
... other php code/includes/etc ...
?>
<html>
... other html elements ...
Not sure if that's the right way to go about it, but it worked for me. If you're using a more extensive doctype, you'll need to escape special characters.
I just spent a day solving this problem where my libraries worked fine on static pages but under a dynamic system with a master script at the start (apache mod_write rewriting all to master script) the browser flipped into backward compat mode (js: alert(document.compatMode()) ) and distorted my styling. All my include files were ended properly and no echos, etc.. The problem? A blank line above the opening <?php of the master script.......
You may not believe but I have a MAGIC way to solve this problem:
Upload your documents (which are included before <!DOCTYPE) on your host using File Manager of CPanel, then choose the document and Click "Edit" to see the source code of the document. Then press Ctrl+Home then press Delete!
You see that nothing will be deleted but that hidden white space!!
Save your document and you will notice that everything is OK now.
I do this for all of my projects
In my case this works fine:
$ brew update
$ brew install coreutils
$ cd directoryWithSymfony2Project
$ for file in $(find ./ -name '*.twig' -or -name '*.php'); do sed `echo -e 's/[\xC2\xA0]//g'` $file > temp; echo 'Processing ' $file;rm $file; mv temp $file; done
I had the same issue, and the culprit was a whitespace at the top of one of my included PHP files, before <?php:
<?php //Line above this line was the problem
function gggl_vertical_cards(){
ob_start();
?>
//...
do you use session_start() or header() anywhere? then (without outbutbuffering) no whitespace or other character is allowed to send to the client before this functions.