- Linux Systems
- How To Fix PHP Error Notice: Undefined Variable On Line
on this post i show you how to fix an error you might be getting in your PHP script: the error says Undefined Variable On Line. if you are wondering what this error means, i will explain 
Sat Feb 10, 2007
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
basically, this is not a critical or fatal error in your script, it is just a warning or an information error. it just means that a variable in your script you are trying to use has not been declared. if you need to hide these types of warming messages, follow these steps.
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:
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:
now look for this line in the php.ini file:
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:
error_reporting = E_ALL & ~E_NOTICE
Save your changes and then restart you Apache server for the changes to take affect witht his command:
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