I want to chceck files before I'll connect domain on my server. I've added them in direct admin, I've uploaded files - but I don't know how to get to them.
I have 4 domains connected, but i have acces only to one. I saw that it's possible to include file from higher level
include('../../panele-podlogowe.eu/adm/img/edit.gif')
That gave me correct image. But when I've done:
include('../../panele-podlogowe.eu/index.php');
Nothing happens (I've turned Error reporting on).
When I did something like:
include('../../panele-podlogowe.eu/index.php');
echo 'Failed?';
Nothing prints out... What the heck?
Solution:
ini_set("display_errors", "stdout");
Review the PHP error log. That usually, even under default settings, shows what's the problem.
Enable error reporting so php will print what is wrong. Add this at the top of your file.
error_reporting(E_ALL);
Otherwise:
Check the access permissions for that file
Double-check the file you are including for syntax errors. (if the include causes php to crash/segfault you might not get any output)
Related
I'm trying to see what error PHP is producing. So I've changed the value of dispaly_errors to ON in the etc/php5/apache2/php.ini file.
The file doesn't display anything and I don't see any error on the webpages.
Am I missing any thing?
First, you have to make sure that this is your correct ini file. Usually the file you have used is the correct one. If not sure, you can create a simple PHP program to call the phpinfo() function and check this out.
Next, you have to restart Apache. Without a restart your settings don't take effect.
Another thing... This file can be a little misleading because there are so many comments in it. The actual line to change is way down. On my setup (LAMP/Ubuntu) the setting is on line 538.
Open php.ini file from your php folder, remove semicolon from all error reporting like
;error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT, ;display_errors=On etc, at last, restart your server, you will find all error messages.
Another way for showing error, you can write these codes in your script -
echo '<pre>';
error_reporting(E_ALL);
ini_set('display_errors', 1);
In addition to enabling display_errors, you may also need to set the error reporting level. if you are expecting errors with a script that is redirecting, be sure to turn off the redirection or you may never see them.
So I'm coding php on a friends site and the hosting provider has hid the php error log somewhere we haven't been able to find. It would be very useful in debugging the code, is there some code I can add to the top of the script to record the errors in a file I pick?
Edit: I've tried Dagon's suggestion with a test file with the following code:
ini_set("log_errors","1");
error_reporting(E_ALL);
ini_set("error_log", "/actual_file_path/Errors.txt");
print_r(file_get_contents("/actual_file_path/Errors.txt"));
fake_function();
The file path is correct because print_r(file_get_contents("/actual_file_path/Errors.txt")); is printing the text I added to the file. When the page dies form calling fake_function() nothing is recorded in Errors.txt. Really strange.
I'd like to see any PHP errors that are occuring, ie the "Expected ; on line 5 of myfile.php" sort of thing. Unfortunately, I cannot seem to figure out how to see this information.
I've set E_ALL, display_errors ON, friendly error messages are turned off, IIS is set to pass-through on errors, what am I missing?
Syntax errors used to show up as stated above on any page; they no longer do. We moved the server to a localhost for development, and I guess didn't mimic exactly the server config. Now I'm stumped.
Tried on IE and Chrome, neither of which show the errors.
Errors are logged in PHP's log file, but I'd still like them to be displayed on the page; at least for now.
UPDATE:
Just tried adding ini_set('display_errors', 'on'); directly into the requested page, and it now works.. but why? Why does it need to be set locally? My PHP.ini file has this declared already.
To answer the first part of the question; to see the errors when using ajax: You can use the developer tools of your browser to see the exact response from the server.
In FireBug for Firefox for example, you go to the Net tab and there you see all ajax request popping up as they happen. Opening one of these requests will give you an overview with more tabs like Response and HTML.
Try using:
error_reporting (-1);
E_ALL isn't really "all" for php < 5.4.
Also, make sure 'display_errors' is set.
ini_set( 'display_errors', 1 );
Well, looks like this is half my own stupidity, half the cloudiness of automatic installations.
Turns out there were TWO php.ini files, and that IIS used the one located within the iis express directory on the main drive, instead of the regular PHP directory.
So to anybody else having this problem, I'm providing the full list of crap you have to wade through to get the errors as you would like:
1) Turn off the IIS default error pages
2) Disable 'friendly error messages'
3) Ensure you are using the CORRECT php.ini file, and change the parameters as needed. Specifically error_reporting and display_errors.
All of this is necessary before seeing all of the error messages you need right in the browser.
I developed a php project in WebMatrix on IIS. In this project I accidently initialed same "session variable" twice.
Example: File - a.php
<?php
$_Session['one'];
include 'b.php';
...........
...........
...........
...........
?>
Example: File - b.php
<?php
$_Session['one'];
...........
...........
...........
...........
?>
When I run this project from Webmatrix(IIS server) this error wasn't shown but when I ran this project on Apache this error was displayed and I corrected my flaws.
Warning on Apache:
Notice: A session had already been started - ignoring session_start() in D:/path/.
My question is that why this error was not shown earlier? Is it something related to IIS server or WebMatrix. I always need to be aware of the errors or warnings in the code so that I can get rid of them and the efficiency of the code is sustained, please do suggest me some ideal php develeopment tools which can catch even minor errors in my code.
Ensure errors are being displayed and then try turning error_reporting all the way up at the beginning of the application.
ini_set('display_errors', 1);
error_reporting(E_ALL);
Also, be aware that Windows is not case-sensitive. You could say include 'A.php' or include 'a.php' and it would not care. However, when you put it on a Linux-based server, which is case-sensitive, it may not be able to find the file A.php if its actually a.php.
It's possible you got errors because the first server was running PHP 4 and the second is PHP 5. Double-including a file containing functions will get different results in those versions. See the text just before example 6 in this link: http://php.net/manual/en/function.include.php
EDIT: I believe the error messages generated in your edited post indicate something of a different nature.
For files that you want to make sure they are only included one time, use include_once(). http://www.php.net/manual/en/function.include-once.php
There are some situations where you may legitimately want to include() twice from a file. But because those situations are rare, it's best to use include_once().
Warning on Apache:
Notice: A session had already been started - ignoring session_start() in D:/path/.
You can't start session again which is already started.
You need 1 session start at a.php when you include b.php it can use started session.
Its a warning and warning means its not good but php can fix this error and continue working.
Its all about error reporting level.
It is hard to tell if the error didn't occured on IIS or not. Only because it was not displayed or logged, does not mean it didn't occur. Please compare the error reporting php.ini configuration between both systems.
Another thing you should compare in configuration is if session auto-start had been enabled on the old or new system or not. This might be triggering your error, but it's only a guess. As written the error might have been already on the old system but just was unnoticed.
How would I go about changing where PHP logs it's syntax errors? I've got multiple people working on the same server, and I want to be able to send my own logs to a custom file so that I'm not looking at every one else's errors.
I can do this:
error_reporting(E_ALL);
ini_set('display_errors','On');
ini_set('error_log','path/to/mylogfile.log');
And that works for some errors, but for actual syntax errors, the logs are still being sent to the master /var/log/httpd/error_log. How do I make the syntax errors get sent to my custom log file?
Since the file cannot be correctly parsed, the ini_set function is not executed either and neither is the new error log set. You need to set php_value error_log /path/to/myfile.log in an .htaccess file or the global server config (I'm assuming that you're using Apache).
Given that syntax errors prevent PHP from running you will not be able to set log paths via PHP. It's a chicken before the egg situation.
Alternatives would be:
Change the error log at the webserver level
Enable output of error messages to the browser
I'd suggest the latter.