Hello,
Im just wondering what I do to remove this error from my site:
Notice: Undefined index: page in C:\\Webserver\\Apache2\\htdocs\\index.php on line 58
This is the code around line 58, at first I though it was because I didnt set a default, but that doesnt fix the problem.
<?
switch ($_GET['page']) {
case "register": include('includes/register.php'); break;
case "login": include('includes/login.php'); break;
case "help": include('includes/help.php'); break;
case "add_reg": include('includes/add_reg.php'); break;
case "news": include('includes/news.php'); break;
//case "check": include('includes/check.php'); break;
case "error": include('includes/loginerror.php'); break;
case "activate": include('includes/activate.php'); break;
case "s_activation": include('includes/send_activation.php'); break;
case "activation": include('includes/activation.php'); break;
default: include('includes/news.php');
}
?>
Please help its annoying to have that silly error message
Thanks
James
ArcanE
August 23, 2006, 7:20pm
2
This mean there isn’t a page variable set in your url. The url the code is expecting is index.php?page=test while yours probably is just index.php
These kind of notices are generally harmless and can be ignored. You can switch the displaying of errors of by putting this in your code which displays all errors and warnings but no notices
error_reporting(E_ALL ^ E_NOTICE);
or if you want to turn of all errors all together you could try
ini_set("display_errors", 0);
It’s probably referring to the $_GET[‘page’].
If you call that script with page=something in the url, does that fix it?
If so, put “if(isset($_GET[‘page’])){ … }” around your case/switch
yes bkennedy that was the problem, thanks for the quick replies peeps!
I can’t duplicate, but the missing index must be from the GET array. How about a wrapper to catch?
if(isset($_GET['path'])) {
//your switch block here
}
else {
// your default value again
include('includes/news.php');
}
…I’m obviously too slow!
if you wrap it with an isset, then his default case will never be true.
you could either
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = '';
}
switch ($page) {
}
// or just
switch (@$_GET['page']) {
}