How To Fix PHP Error Notice: Undefined Variable: Index In X/x/x.php Line X

Forums » Linux Systems » How To Fix PHP Error Notice: Undefined Variable: Index In X/x/x.php Line X
This Page Contains information about How To Fix PHP Error Notice: Undefined Variable: Index In X/x/x.php Line X By webmaster with 19 Replies. Last Upated: Fri Apr 11, 2014
on one of my website, i kept getting this error on a new script i just installed on a brand new linux server provided by Webune.com which i just leased a dedicated server from Webune.com

this was the errors:
Notice: Undefined variable: leftLinks in /var/www/home/shop/script/header.php on line 124

Notice: Undefined variable: q in /var/www/home/shop/script/header.php on line 138

Notice: Undefined variable: welcome in /var/www/home/shop/script/header.php on line 148


I was trying to figure out how to fix this error, i contacted the support team at Webune and they were able to give me an answer quickly.

so just in case it happens to me in the future, i can have this tutorial guide to remind me on how to fix this PHP error. or if anyone has the same problem they can benefit from the support team at Webune Web Hosting.

so to fix this error you need to login into you Webune Dedicated Server. If you are not a Webune cusotmer, make sure you are having this problem on a linux server like Red Hat, Fedoar, Centos etc..

To start login as root using a SSH connection to your linux shell prompt.

make a backup of the php.ini file with this command:
CODE:
cp etc/php.ini /etc/php.ini.backup


then open the php.ini file with a text editor, i wll be using nano which comes with linux, you can also us VI, but i like nano better. i will open it using nano with this command:
CODE:
nano /etc/php.ini


now look for this line in the php.ini file:
CODE:
error_reporting = E_ALL
NOTE: you may have something different set for the error_reporting , just make sure you make the changes on the line without a semi-colon because a semi-colon at the begining of the line mean its a comment

So now change it to:
CODE:
error_reporting = E_ALL & ~E_NOTICE

Save your changes and then restart you Apache server for the changes to take affect witht his command:
CODE:
/etc/init.d/httpd restart

once your Apache server restarts, go back to the page where you were getting this error and refresh the web page and you should not see this error anymore.

Hope this help. Please provide any feed back or comments you have by submitting your reply at the bottom of this page. thanks
ming
// error_reporting = e_all
error_reporting = e_all & ~e_notice
desbest
works great! why i have to have an error everytime a php variable isn't defined yet i dunno. even if(defined($var)){} or if($var == ""){} don't work without your fix.
Raghu
thanks for the solutions
for warning messages
we have to set
allow_call_time_pass_reference = on

regards,
raghu
saravanan
thanks for ur blogs.that message was killing me for 2 hrs it got healed coz of ur blog.
thanks
Christian
thx! just what i needed..
Muyiwa
wao! this is great. thanks.
earler
sorry guys but just switching off the error message doesnt fix an php-error.
it just hides it in apache logs
David
You didn't fix the problem, you just found a way to ignore it. You still have three undefined variables.
martin
Please help me. am uploading my php code on greenwich server and i keep getting this type of error on my page as shown below. what should I do ?

Notice: Undefined index: response in /home/mm652/public_html/i on line 3

Notice: Undefined variable: articleheading in /home/mm652/public_html/i on line 37

if i try it on my machine all is fine.
yash
You didn't mentioned your code. Any way those are notice, you can ignore it by writing error_reporting(0); at the top of your page.
Jaysun
This is absurd! You are not fixing the problem, you are simply hiding it - the error still exists AND in many cases would leave a site open vulnerable to attacks!
Aldo
Very Thanks!!!!!
Jim
LOL JAYSun is such a noob! i run code he said and it fixed, so it obviusly works. NOOB jaysn. LOL..
Alex
You are NOOB actually, Hiding != Fixing
suruchi
gr8 it works thnx
Colin
- at - Alex totally! I am angry using WordPress plugins from developers that never check to make sure the property/object is available! Even wordpress itself is falls foul of this. I have "fixed" the wordpress install I have but won't deploy it. Might do an article about it!
mirza
Thanks very much for the solution. For the notice error in php5
Tedley
use either "if(!empty($fu) or "if(isset($fu[' instead of "if $fu{}" or "if $fu['#bar']{}"
http://wallpaperama.com/forums/how-to-fix-php-error-notice-undefined-variable-index-in-x-x-x-php-line-x-t801.html
Maryjane
Sounds like you need to initialize your variables. Look at initvar()
Title: How To Fix PHP Error Notice: Undefined Variable: Index In X/x/x.php Line X [2881]
Tags: how to fix php error notice undefined variable index in x x xphp line x
By , 19 Comments