Notices are really recent in PHP development, and they are not errors, which means you don't have to fix them. Yet, this is a very good practise to do so.
The undefined index
notice warns you that you are trying to read an array index that hasn't been initialised. In your case, you try to read the home
index of the $_GET
array. When your URL is something.php?home=something
, then $_GET['home']
is initialised automatically, and no notice appears. However, when you access something.php
, this index isn't set, which explains the notice !
In your code, you need to check whether this index is set, and assign it a default value when it isn't.
$page = isset($_GET['home']) ? $_GET['home'] : 'home';
In this case, if the home
index isn't set, $page
will be set to "home". See http://davidwalsh.name/php-shorthand-if-else-ternary-operators if you want to know more about the ternary operator (? and :) which I've just used.