PHP & MySQL - Error Question - php

I was wondering how can I stop PHP & MySQL errors from displaying to users but still have the errors logged in the server so I know something is wrong.

two ways:
Config your php.ini (turn error off)
Put a # after any action...
Example:
<?php
$a = #mysq_query("a bad query");
echo #$b; // $b donst exist, so thrwos an error but with the # dosnt show anything
?>

I want to point out that there is a good reason to surpress MySQL Errors. If there error gives away too much info about your database set up and schema (by showing the query in the error... joins... etc.) you don't want a live site showing those errors to the public. Of course you would want to log them. So in the interest of security this is a good single reason to not display them on a live site. As I said logging yes. Displaying no.

http://www.php.net/manual/en/errorfunc.configuration.php
Set display_errors to zero and define a log file with error_log in your php.ini or with ini_set or something.

Related

Wordpress - The7 Template - On every page I have 4 Warnings and do not know how to disable it in menu or php site/content

I have a problem with my Wordpress site, more specifically, The7 template. On every page, including the main page at the bottom of page below footer I have 4 Warnings which are the same:
“Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wp_filter_content_tags’ not found or invalid function name in on line”
I do not know how to solve it/turn it off. Could you tell me which PHP page or what exactly cause this problem to appear? It’s really annoying. Due to the fact that it is in the main body and not in any div/b/p/etc. tag I cannot hide it with CSS just for a while.
Kind regards
Peter
Hiding error reporting on prod
On prod you want to avoid showing errors, due to security and user experience reasons. To achieve this, in PHP you can run
error_reporting(0);
or, even better, in php.ini, you can have this line
error_reporting = off
What the error means
The error tells you that a function is to be called by name, but it does not exist. wp_filter_content_tags does not exist in your context.
Solution to the error
Even though you have hidden error reporting on prod, you still need to show errors on dev and that function might do something very useful. From the doc you can see that it's located in wp-includes/media.php. So, if you do not need to call this function, then search for its calls and remove them. If you need this function, then require or include it into your files. If, for some reason you cannot remove this function (for ex. you do not want to hack a template that might have some versions in the future), but the function/file is not helpful for you, then you can implement a function with the same name.
Thank you very much for answer. I used it to find solution and in my case there is a need to change wp-config.php a little bit. It means to add these specific lines to code:
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false)
In my case it worked and no more errors / warnings showed on every / main pages.
Kind Regards
Peter

joomla specific component displaying blank page

I try to access my custom components on view and sub controller like
http://www.whizzrd.com/administrator/index.php?option=com_osservicesbooking
I have tried everything, still i didn't know what is the error.
1.added this code on com_yourcomponent/yourcomponent.php
ini_set( 'display_errors', true );
error_reporting( E_ALL );
enable debug in global configuration and set the error_report to development
but I'm still getting blank pages. still not yet find the error
Thank you in advanced
Go to Global Configuration in Admin panel and Server Tab and there do Error Reporting to Maximum.
Doing this setting you will be able to view the error you are getting.
Global Configuration-> Server-> Error Reporting -> Maximum
Try with adding your view name.
http://www.whizzrd.com/administrator/index.php?option=com_osservicesbooking&view=osservicesbookings
Also check filename and component names if it seems differ or capital.
My problem was that I had typed defined('__JEXEC') or die (two underlines before JEXEC) and it is supposed to be defined('_JEXEC') or die and as I had not set a message for die it basically just displayed a blank page with nothing. Took me a couple of hours to figure it out. Best thing I did was to start adding a different message in my die statements and then it will display the die message of the page with errors.

PHP 5.4: disable warning "Creating default object from empty value"

I want to migrate code from PHP 5.2 to 5.4. This worked fine so far except that all the code I use makes extensive use of just using an object with a member without any initialisation, like:
$MyObject->MyMember = "Hello";
which results in the warning: "Creating default object from empty value"
I know that the solution would be to use:
$MyObject = new stdClass();
$MyObject->MyMember = "Hello";
but it would be A LOT OF WORK to change this in all my code, because I use this many times in different projects. I know, it's not good style, but unfortunately I'm not able to spend the next weeks adding this to all of my code.
I know I could set the php error_reporting to not reporting warnings, but I want to be able to still get other warnings and notices. This warning doesn't seem to be effected by enable or disable E_STRICT at all. So is there a way to just disable this warning?!
Technically you could do this by installing your own error handler for warnings. From inside the handler check the string error message; if it's the one you want to suppress then return true, otherwise return false to let the default error handler do its thing.
However I would still recommend doing the right thing and manually fixing your code wherever this misuse does appear because, if nothing else, it gets you into the correct habit. Unless this is paid work (in which case there usually are concerns that override purity of implementation), consider this as a lesson and do the right thing.
I know I could set the php error_reporting to not reporting warnings, but I want to be able to still get other warnings and notices.
Don't disable the error reporting, leave it at an appropriate level, but disable the display_errors directive:
ini_set('display_errors', 0);
There's no reason to print notices to the screen in production.
Then as Jon said, use a custom error handler if you aren't already, example:
function my_error_handler($error_level, $error_message)
{
// write error message to log file
}
set_error_handler('my_error_handler');
You can pass in the error reporting level to the second param of set_error_handler. This way you can take your time and do the right thing, which is fix the code to stop generating notices.
If you're moving a lot of sites over to 5.4, you can probably have your server admin turn off display_errors in php.ini until you have enough time to fix everything. Better yet, stage everything and fix it before upgrading, but that may not be an option.
you really could use an IDE for php and try to do this:
Search for $MyObject->MyMember = "Hello";
Look for the results and if it brings the right things, try to replace that with:
$MyObject = new stdClass();
$MyObject->MyMember = "Hello";
So maybe the IDE would do the long work for you...
I had the same problem i handle it like bellow in production environment
\error_reporting(\E_ERROR);
I have to say that my application doesn't need/generate errors, it's on a very controlled environment so doing this wouldn't hurt much, but if your application is an error prone one you should have you own error handler and with a proper regex and preg_match ignore the “Creating default object from empty value” warning and log/prompt others at your discretion.

Tried to hide any error messages, but it still appears

I'm using php 5.2.13 and Oracle database.
And I'm trying to hide error messages, but doesn't work.
I tried to...
add this code to the page where an error occurs
ini_set(display_errors,0);
set an option in php.ini
display_errors = Off
...and what else should I do?? I thought I had done enough.
And the error message is coming from Oracle like this;
ORA-01400 cannot insert NULL into .....
I wonder if there's any modules in php that display error messages..?
thanks.
This is not a PHP error, but a Oracle error, your column can't be null - you need to specify a value. That's why your display_error's doesn't hide this error.
I have to emphasize - like others in the comments - that the only good error is a fixed one.
How about using LOG ERRORS INTO on your DML, this should allow you to dump your errors to a table for later inspection.
see: http://www.oracle-developer.net/display.php?id=329
and: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#BGBDIGAH

PHPMyadmin does not show mysql error messages

I installed phpMyAdmin on my site and it works. But when I mistype a query it does not show the mysql error message only the error code.
1064 -
I expect the following:
1064 - You have and error in your blah blah...
Without an error message it's difficult to know what's wrong.
In my php scripts I'm able to get the error message via mysql_error(). But myAdmin shows nothing.
I googled a lot but I didn't find anything useful.
How can I make it show the error messages?
Any ideas?
Judging by the fact that you get "#1064 -" as output, I can find only two places in the phpMyAdmin 3.3.9.2 source where the error could be occurring. The first is in the call to mysql_error or mysqli_error, depending on which backend your installation is using. I see you said that mysql_error works fine; if the phpMyAdmin information page you get when first logging in indicates that mysqli is being used, you might want to check that too.
But if mysql_error works, it seems more likely that the problem is in phpMyAdmin's character set conversion function PMA_DBI_convert_message in libraries/database_interface.lib.php. You can confirm this easily enough by inserting return $message; at the very top of that function, bypassing everything else in there. If that makes it (more or less) work, you'd probably want to determine what $server_language and $GLOBALS['charset'] are getting set to; see if the conversion is using iconv, recode_string, libiconv, or mb_convert_encoding; and then try to work out why whichever of those is failing to convert the error message properly.
Probably, Server cannot correctly access LOCALE settings. It happens on chroot-ed / chjail-ed environments or poor configuration.
Based on #Anomie answer, I made a workaround.
For phpmyadmin 4.4.3 change the Fallback setting in file libraries/DatabaseInterface.class.php
/* Fallback to CP1252 if we can not detect */
$encoding = 'UTF-8';
For some older versions, edit file libraries/database_interface.lib.php and set
array $encodings => 'english' value to UTF-8 (~line 273),
'english' => 'UTF-8', //'latin1',
Did you see :
$cfg['Error_Handler']['display']
boolean
Whether to display errors from PHP or not.
$cfg['Error_Handler']['gather']
boolean
Whether to gather errors from PHP or not.
In the docs ?
Had the same problem, which was solved by disabling the FireFox add-on uBlock (version: Origin 1.25.2) in my browser for phpmyadmin.

Categories