Jump to content

Archived

This topic is now archived and is closed to further replies.

stobbo

Help with Error

Recommended Posts

Hello.

I am fairly new to PHP, and am struggling over a error. Any help would be kindly appriciated.

Error:

[code]Notice: Undefined index: id in c:\home\********\public_html\index.php on line 3[/code]

Code

[code]<?php
include("/home/********/public_html/modules/template-top.php");
$page= $_GET['id'];
if(file_exists("/home/********/public_html/content/".$page.".php"))
{
include("/home/********/public_html/content/".$page.".php");
}
else
{
include("/home/********/public_html/modules/news.php");
}
include("/home/********/public_html/modules/template-bottom.php");
?>[/code]

If you can help, I would be most pleased.

Thanks, Stobbo.

Share this post


Link to post
Share on other sites
This will happen when $_GET['id'] hasn't been defined. Try...
[code=php:0]
<?php
include("/home/********/public_html/modules/template-top.php");
if(isset($_GET['id']) && file_exists("/home/********/public_html/content/".$_GET['id'].".php"))
{
include("/home/********/public_html/content/".$_GET['id'].".php");
}
else
{
include("/home/********/public_html/modules/news.php");
}
include("/home/********/public_html/modules/template-bottom.php");
?>
[/code]

Share this post


Link to post
Share on other sites
It means that $_GET['id'] isn't set

If someone goes to pagename.php there is no $_GET['id'] as averse to pagename.php?id=1 in which case it is 1.

You need to check if it exists first of all...

[code]
<?php
$page = isset($_GET['id']) ? $_GET['id'] : defaultvalue;
?>
[/code]

This will set it to $_GET['id'] if it exists or to a defaultvalue (you'll need to set that) if it doesn't.  Also, make sure you're checking the contents of $_GET['id'] before using it, otherwise a user could potentially request any file.

HTH

Dest

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.