One of our websites earlier today started outputting a few PHP warnings that were only visible through Firefox but weirdly the errors wouldn't show in Chrome or Safari.
I had a look at the request/response headers and noticed in the response header for Firefox the entry
X-pad: avoid browser bug
Could this be the reason for the discrepancy in between the two browsers? From what I could find, X-pad was a work around for a bug that existed in an ancient browser.
Below is a screenshot of the errors from Firefox.
Error Message
Edit.
Found out the cause of the error and also why chrome wasn't showing the warnings. A number of pages on our site had been injected with some code, as documented here. The code was ignoring safari and chrome , but not Firefox. Hence the discrepancy.
As for the fix, simply remove any instances of the code. Affected, were instances of index.php/template.php/page.php files.
Uninitialized string you get because your variable is not setted in an array. Make sure that is setted.
if (isset($somevar['var']))
{
// etc..
}
Your session_start() code is NOT on your TOP in a PHP file. A session_start() should be called before all scripts executed.
To turn off showing errors manually via PHP put on top:
ini_set("display_errors", 0);
Put all your errors to error.log file instead of showing errors on PHP production environment.
X-Pad is header appender to the response from apache. So this isn't way what errors occured. X-Pad doesn't relation with your errors.
Related
So I am using xampp as my server hosting, and haven't got a problem in years. But I found something strange happening.
I have this code:
require "init.php";
require_once('vendor/autoload.php');
$pdf = new TCPDF("P", "mm", 'A4', true, 'UTF-8', false);
var_dump($pdf);
If I execute this code. My page is fully blank? And sometimes it isn't. Like so:
But when I execute my page in a command line, like so:
c:\xampp\php\php.exe C:\xampp\htdocs\websites\Traject-Parket\index.php
I get the var_dump I wrote.
So I have no errors whats so ever? How come my page is blank and sometimes isn't? Because in this project nothing seems to work but in other projects it does.
Blank pages (or WSOD, white screen of death) is when your script fails.
You don;'t have display_errors turned on, so at the top of your script, you can say:
ini_set('display_errors', true);
error_reporting(-1);
And that will allow you to see the error.
However, it isn't the best way. Error logging directly to the screen not onl;y distorts your page, but can ruin header() calls, as the HTTP body has already started outputting and thus no more HTTP headers can come out.
For the best error logging experience, set error_reporting to -1, turn display_errors off, and set a custom error_log. Then in the terminal, type tail -f /path/to/error_log. Your notices, warnings and errors will now scroll past in real time, without distorting your web page's display.
I don't know this library, but var_dump shows that unprotected data from PHP 5.6.0.
Maybe the problem comes from there?
Look at the __debugInfo() method
And give us the exit.
In the php manual (http://php.net/manual/en/function.header.php) I find the following about http headers:
QUOTE
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
ENDQUOTE
I tried this now (making a study of the HTTP protocol) and find that this doesn't seem to be an issue anymore; I wonder what has changed: has the way php deals with parsing webpages changed? I tried several browsers (Chrome, IE10, IE7) and OS (Windows 8.1, XP) and none of them seem to have an issue with this anymore (see informaticaschool.net76.net/httpdemo3.php for a page that includes exactly the above code example, not giving an error.
For the details of the php version running on that server (I also tried a different apache server) see informaticaschool.net76.net/phpinfo.php.
I admit its a bit of a strange thing to ask why an error does NOT occur but as pointed out i'm studying the workings of http. Looking into a Wireshark trace now to find out what happens exactly in this case, that I knew to be an issue before, I am now surprised to find that NO error appears (and not finding an explanation for it in the php manual).
That server has output_buffering turned on, so all output is buffered and held, which allows you to send headers to the web server even after you have already produced output. See the canonical answer about this issue, section "But it worked on the other server!?".
You must send headers before send output buffer.
Or you can use functions ob_start and ob_end_flush to save output buffer.
I have a problem with PHP. There is an error that I have never encountered before. The home.php, which is the main page of my site, cannot be viewed. And there is nothing in error log. After there is an inclusion of a php page (a class that is a part of my API). Till that line the holl HTML (javascript and css inclusions) are echoed from php and successfully rendered in browser, but after the php kind of stops suddenly. When I delete that line(php page inclusion line), website works, but before, this inclusion didn't make any problem for me. I removed the code parts which after them I encountered this problem, but nothing works.
I am using Apache2, PHP5 with Ubuntu 11.10.
Any help will be appreciated, thanks in advance.
My first hints would be to check the following:
In your script set ini_set('display_errors', '1'); and error_reporting(E_ALL); to display all errors.
Turn on the php error log and check it for errors.
run php -l home.php on the command line to check your php file for syntax errors.
Check Apache's error log, sometimes error messages go there.
If nothing helps use a debbugger like XDebug to see where the script terminates, or alternative insert statements like die("here"); and move them around in your code, to see which parts of your scripts are passed.
Greetings and good luck.
I have the following tag for when a user is successfully logged in:
header('Location: /members');
It always used to work. Now, however, when I try to load the page, Chrome gives me this error:
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
On Firefox, I just get a blank page. When I comment the header statement out, it works, but without the redirect (obviously).
I have tried it with output buffering on and off, with the same effect. Any ideas?
Edit: I have a PHP header statement at the beginning of the code that redirects users to the member page if they are already logged in. Could this be affecting it? I'm not getting any headers already sent errors...
Just put error_reporting(E_ALL) and ini_set("display_errors", 1) and you'll see what's wrong.
Install the HTTP extension and use this instead:
http_redirect('/members');
This should do the trick. If you don't have it installed. you can mimic what it does. It's explained in detail on the manual page, the steps in short:
Create an absolute URI from the relative URI as redirects by RFC must have one.
Check if headers have already been send, if so don't send header, otherwise do.
Display a HTTP response body with the link of the redirect.
Exit the script.
If you don't follow the specs, you can not expect that things work with a browser. Many examples given in the internet are not giving conform redirects, so don't be misguided by bad examples.
Next to that - as already suggested by others - turn on error reporting on your development box so you are aware of any notices and warnings that your code produces. Deal with those issues as well.
So I just got a nasty surprise when I deployed some code I thought I'd tested. It would seem there must be some difference between my test machine and my server. The exact same code, featuring a header redirect, worked perfectly on my test machine and not at all on the server. The redirect on the server simply didn't happen, leaving a blank page as a result.
The header is called somewhere in the middle of the script - but nothing will have been output yet. It doesn't output anything until the very end of the script. Long after everything else is run. It buffers everything.
Both server and test machine are running the same PhP version, the same Apache version. Is there something in the configuration files that would allow the header to happen for one and not in the other? Is there something else going on here that would cause it to fail?
EDIT:
Here's the line that sets the header:
public function setRedirect($url) {
header('Location: '.$url);
}
And here's the code that calls that:
$url = new URL('index');
$this->layout->setRedirect($url->toString());
Where URL::toString() always generates a fully qualified domain name, in this case: http://domain/index.php?action=index
I checked both Php and Apache error logs. Nada.
Probably there was some whitespace or other form of output before the header call.
This is only work if you the ini setting output-buffering is on (or if you explicitly start output buffering, but in that case, the redirect should work in both computers).
You can confirm this by turning on error reporting.
Use Fiddler or some other client-side tool to check your headers. Determine that the Location: header is actually being sent. Also, some browsers are picky in the order that headers need to be sent.
I think the most likely explanation is that an error is causing the script to exit on your server, and you have display errors turned off (hence the blank screen). I would suggest checking the Apache error long on your server to see if PHP is putting something in there.
Otherwise you could use a browser extension like LiveHTTPHeaders (for Firefox) to see if the location header is being sent at all, or try debugging the script to see if it's even getting as far as that header call.
I think your server puts some script in your pages to track visitors and give you traffic stats or for a similar purpose. Ideally, you should get an error for this but may be your server has error reporting disabled which gives you a blank page.
I suggest you to run a script with a syntax error and check weather your server has error reporting disabled.