How To Fix PHP Error Notice: Undefined Variable On Line

Forums » 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
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 which i just leased a dedicated server from

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:
nano /etc/php.ini

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:
/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
// error_reporting = e_all
error_reporting = e_all & ~e_notice
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.
thanks for the solutions
for warning messages
we have to set
allow_call_time_pass_reference = on

thanks for ur blogs.that message was killing me for 2 hrs it got healed coz of ur blog.
wao! this is great. thanks.
sorry guys but just switching off the error message doesnt fix an php-error.
it just hides it in apache logs
You didn't fix the problem, you just found a way to ignore it. You still have three undefined variables.
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.
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.
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!
Very Thanks!!!!!
LOL JAYSun is such a noob! i run code he said and it fixed, so it obviusly works. NOOB jaysn. LOL..
You are NOOB actually, Hiding != Fixing
gr8 it works thnx
- 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!
Thanks very much for the solution. For the notice error in php5
use either "if(!empty($fu) or "if(isset($fu[' instead of "if $fu{}" or "if $fu['#bar']{}"
Sounds like you need to initialize your variables. Look at initvar()
Title: How To Fix PHP Error Notice: Undefined Variable On Line [2881]
Tags: how to fix php error notice undefined variable index in x x xphp line x
Comments 19
Visits 21432