when a query doesn’t match e.g user name and password, the localhost returns an warning message. how can i turn it off?
i think there is some
Can someone guide me please?
waning message is this
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 2 in /var/www/login/loginform.php on line 24
Edit your PHP.ini file :
Set these two lines as :
display_errors = Off
display_startup_errors = Off
You really should fix whatever's causing the warning, but you can hide / show errors with error_reporting. To hide warning messages, you could use something like this:
error_reporting(E_ERROR | E_PARSE);
You must fix your code rather turning it off.
If you want to off warnings you can set it in php.ini of your server. Set
error_reporting = E_ALL & ~E_NOTICE
I recommend doing this globally is not a good idea. So do it in your project using PHP. To do this you can use PHP function
error_reporting(E_ALL ^ E_NOTICE);
Put this function before where your code starts execution.
Related
Ok so PHP has the function ini_set() which a lot of people are aware of and will use to set various configuration options (here) to help with development etc. However, this function does only seem to work at runtime and will not work if there are any fatal errors or the script has syntax errors and can't be parsed / compiled.
Therefore surely there is no point of doing this (from the manual):
http://php.net/manual/en/function.ini-set.php
Examples
Example #1 Setting an ini option
<?php
echo ini_get('display_errors');
if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}
echo ini_get('display_errors');
?>
I don't know if I'm just missing something and my php.ini isn't configured correctly, but a lot of the time I get no errors. For beginners / juniors there will no doubt be a lot of syntax errors (missing semi-colons, closing brackets etc), and said juniors would search for how to turn on errors, assume the above manual entry is correct, yet when re-running their script, alas, they get no errors as the script cannot be parsed / compiled in the first place.
I know you can set display_errors = On in the php.ini file and restart your web server to show all errors to the screen (using this in a development environment, definitely not live), but wouldn't it be better just to remove the function and only configure the php.ini file for different error levels?
Update:
I know ini_set isn't just for displaying errors, but code can't be very manageable if you're calling ini_set in certain scripts / functions / files and wouldn't it make more sense to use the php.ini for something like that?
Update
So the ini file can be used to set global configuration options, surely you'd use this for security or optimisation, however developers could still use ini_set to override some of these options at runtime which may not be desirable
In summary (#Hanky웃Panky):
Why do I have the option of displaying errors when some trivial syntax errors will still not display?
yes, you are right that its better just to remove the function and only configure the php.ini file for different error levels.
But, this is good only that case when you have only one project in your machine, So, its all configuration setting you can do in php.ini
Consider, the case if you have multiple project setup. if you don't want some settings in that project still it will get from php.ini
So, it is suggested for some configuration settings you just set them at project level with ini_set() and will not reflect other projects.
string ini_set ( string $varname , string $newvalue );
The Purpose of ini_set is to set the value of the given configuration option.
This newvalue is kept by the configuration option during the script execution and restored at the scripts ending.
Example for setting an ini option
<?php
echo ini_get('display_errors');
if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}
echo ini_get('display_errors');
?>
string ini_set ( string $varname , string $newvalue )
Basically ini_set() sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
for all the variables which you can configure during the script run. please go through the below link.
Another settings can be configured at runtime using the the ini_set() function:
memory_limit and max_execution_time
(From ZCE test part about PHP Basics).
ini_set — Sets the value of a configuration option. Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending, without ini_set(), values from php.ini file will be used.
EDIT:
You may find this helpful:
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
My PHP web-app sometimes returns this Fatal error on Line XXX due to reasons like extremely-slow-connection speed. Although, this occurs rarely, like 1 in 1000 times, I want to avoid such output on the browser. I am doing error logging on server side for some functions. So, I don't want to completely disable error reporting. Just that I don't want to display it to the end user.
Various Examples on turning off error_reporting..
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
note : You can put or include() it in any file you dont want to explicit errors. Or if you want to totally off it. Go with tweaks in php.ini file.
Lines to find in your php.ini to tweaks and off error_reporting.
ini_set('display_errors', 'On'); //change to Off
error_reporting(E_ALL); // change to 0
FOR FURTHER INFO :: PHP.NET
To disable any error display to the user of your page, set
display_errors = Off
in your php.ini (this is the recommended setting for production websites anyway!) or
ini_set('display_errors', 0);
in your php.
This display_errors setting only affects the output on the webpage; it will not affect a possibly configured logfile; there the messages still would be logged.
See the php documentation on configuring error reporting: http://php.net/manual/en/errorfunc.configuration.php
Note: The error_reporting setting mentioned by other users here, will, to my knowledge, affect all kinds of error reports (i.e. also what is reported to a possibly configured log file). If you set error_reporting to 0, you won't get any log entries as well. If you want to log something to the log file but not show it to the user, the display_errors setting is the way to go.
on the start of that page write
error_reporting(0);
To avoid issues like this you can set the max_execution_time=1024M to avoid slow speed data generation and to hide errors is must likely error_reporting=0 on the php.ini file.
Or simply:
PHP Code
ini_set('max_execution_time',1024M);
error_reporting(0);
PHP Ini Settings
max_execution_time=1024M
error_reporting=0
Hope it helps.
error_reporting(0); only works if you are not using set_error_handler('my_function'). If this is your case, you have suppress the error message in 'my_function'.
I want to suppress warnings, I searched on SO, found some solutions but they aren't working.
I am getting Warning at following function(file_get_contents) when the internet connection is off. I know this functions requires internet connection, when the machine is not connected this function will show warning.
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vid_id.php"));
first I tried using "#"
then I used error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
then I used error_reporting(0);
can anybody tell me how can I suppress these warnings?
If it's just for a single file, you can suppress the warning using # like so:
$var = #file_get_contents("http://vimeo.com/api/v2/video/$vid_id.php");
$hash = unserialize($var);
But if you don't want to display any errors, you can edit your php.ini file and change the value of error_reporting to 0.
Make sure you restart Apache / webserver after making the changes to php.ini file.
Hope this helps!
I made a huge mistake by mixing result with results and it took me around 4 hours to finally find the bug.
So here is the question, in PHP, is it possible that I can enforce PHP to report errors if I use an undefined/uninitialized variable.
thank you
Set error reporting to E_ALL and ensure that display_errors in php.ini is on.
php.ini
display_errors = On
PHP code
// If you cannot access the php.ini file
// you can do this within your PHP code instead
#ini_set('display_errors' '1');
error_reporting(E_ALL);
The default setting you have right now probably excludes notices, the kind of errors PHP raises on uninitialized variables, which could be something like this:
error_reporting(E_ALL & ~E_NOTICE);
In a development environment I prefer using error_reporting(-1). Which reports all PHP errors.
yes, use error_reporting() and set it to E_ALL, like this:
error_reporting(E_ALL);
Set error reporting to report all errors. Either in php.ini or at runtime using error_reporting(E_ALL)
it already does report an error. something like this:
"Notice: Undefined variable: a in C:\wamp\www\testcenter\index.PHP on line 40"
maybe you didn't go specific enough. but you should try error_reporting(-1); as as if enforces the php to show some recomendations. a piece from the php manual about E_STRICT errors:
Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
just remember that error_reporting(-1); shows more errors than error_reporting(E_ALL); because E_STRICT errors are not included in the E_ALL constraint.
How to turn off this error in wamp:
notice undefined offset
I'd like to turn of just this error, but not all errors.
There are two issues at work here. One is what errors PHP reports, and the second is whether or not it displays those errors on the page (as opposed to the apache error log). If you'd like to turn off just NOTICES:
<?php
error_reporting(E_ALL & ~E_NOTICE);
?>
If you'd like to report the notices to your error log but not display them to the user, do this:
<?php
ini_set('display_errors','off');
?>
Note that turning off display errors will stop displaying ALL errors to the end user, and you'll need to look at the error log, usually located in /var/log/httpd/error_log to see any errors while testing.
Have a look at error_reporting().
You could e.g. set the error reporting to
error_reporting(E_ERROR | E_WARNING | E_PARSE)
But better would be to actually check what is the cause of the Notice and fix it. Then you are on the save side.
E_NOTICE
Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
(If you can't fix the code...) You can exclude notices by setting an reporting level x & ~E_NOTICE, e.g.
<?php error_reporting( error_reporting() & ~E_NOTICE );
or in your php.ini (or similar)
error_reporting=E_ALL & ~E_NOTICE
php.ini => error_reporting = E_ALL & ~E_NOTICE
error->notice undefined offset
main thing is remove the error on your script.Programmer always wish to design program which is error free instead of error hiding.
The array vales are not set, so when PHP is trying to access the value of those array keys it encounters an undefined offset.
$new_array = array('1','2','3');//If I have an array
//We can now access:
$new_array[0];
$new_Array[1];
$new_array[2];
//If we try and access
$new_Array[3];
we will get the same error-->error->notice undefined offset
error_reporting(E_ALL);
ini_set('display_errors', 'On');
ini_set('html_errors', 'Off');
:D
Go to This direction on windows OS C:\wamp\bin\apache\Apache2.4.4\bin
Then open php.ini file by any editor recommended [sublime] in 514 line just paste this two lines.
;error_reporting = E_ALL error_reporting = E_ALL & ~E_NOTICE