Not able to fix "PHP Notice: Undefined variable" and "Undefined index" in code

Shafay Islam

I have been running a Web App for quite some time. The app works even after multiple PHP errors but the error log files are constantly taking 1 GB of my space after every few weeks forcing me to manually delete them. The error resides in a faucet.php file

I am not familiar with Php, I have done everything I can to tackle this error and even check the similar questions but none of it prove to be a fixture of my problem.

These are four error messages and keeps repeating throughout the day.

Undefined variable

PHP Notice:  Undefined variable: refer_file in /home/countnet/public_html/faucet/network/mine/doge/faucet.php on **line 318**

PHP Notice:  Undefined variable: refer_file in /home/countnet/public_html/faucet/network/mine/doge/faucet.php on **line 393**

And Undefined index

PHP Notice:  Undefined index: status in /home/countnet/public_html/faucet/network/mine/doge/faucet.php on **line 604**

PHP Notice:  Undefined index: status in /home/countnet/public_html/faucet/network/mine/doge/faucet.php on **line 608**



**Line 318**     if (!$refer_file) {

**Line 393**     if (!$refer_file) { // the user was referred and the referral isn't saved 

**Line 604**     echo '\'status\': \'' . htmlspecialchars($result['status'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '\',';

**Line 608**

echo '<dl><dt>Status</dt><dd>' . htmlspecialchars($result['status'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</dd><dt>Message</dt><dd>' . htmlspecialchars($result['message'], ENT_QUOTES|ENT_SUBSTITUTE|ENT_DISALLOWED|ENT_HTML5) . '</dd></dl>';

Any help would be appreciated, the app works fine even with these errors but they are now becoming a nightmare as traffic grows.

Kamrul Khan

you need to use isset() or empty() to check if the variable or array index are defined or not.

Line 318 and 393 can be changed to

if (!empty($refer_file)) {

for line 604 and 608 add something like the following before line 604:

$result['status'] = isset($result['status']) ? $result['status'] : 'default_status';
$result['message'] = isset($result['message']) ? $result['message'] : 'default_message';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting error PHP Notice: Undefined variable: do_not_compress in my php code

PHP Notice: Undefined variable

PHP Notice: Undefined variable:

PHP Notice: undefined variable, but they are already defined

PHP Notice: Undefined variable in array_walk_recursive function

Ngnix - FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variable

How to fix "undefined index" notice elegantly?

Fix PHP Notice: 'Undefined index' on Wordpress

undefined index error in php and How to fix it

how to fix undefined index $user = $_GET['user'];

How to fix "Undefined index: link in $_POST"

"Notice: Undefined index: " message for the following code on localhost

Best way to fix PHP error Undefined index - PHP 5.5

Can I fix the undefined index error by changing the website address?

Not able to fix MSDTC error

Not able fix variables python

Undefined Index - Security Risk vs Performance vs Code Bloat

why the demo code in the book gives errors " Undefined index "

What part of my code is causing an Undefined Index error? (PHP)

undefined index - form not sending value through to php code via javascript

undefined index error - image upload same code is working with another example

Notice "undefined index", but this continued to work until I completed the code

How to fix Undefined index if user removes name attr from sign up form php

Undefined index

How do I fix VS Code error: "Not able to determine import path of current package by using cwd" for Go project

Not able to fix the error I get while writing code for analyzing "California Housing" data set from O'Reilly book

not able to compile OpenGL code

Not able to execute the code for ZooKeeperMetaDataStore

Error code from API call from one domain but not other Undefined index: