Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: PHP Error Help

  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Error Help

    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:
    <?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");
    ?>
    If you can help, I would be most pleased.

    Thanks, Stobbo.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    echo $page and see what is getting returned.
    PHP Code:
    <?php 
    include("/home/********/public_html/modules/template-top.php");
    $page$_GET['id'];
    echo 
    $page;
    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");
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It returns the id.

    So if the url is:

    www.domain.com/index.php?id=007

    it will return:

    007

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    if there is no value for 'id' though, then $_GET['id'] will be, as the message suggests, 'undefined';
    You can test for the value being there with either isset() or empty(), and include that in your conditional.

    Regardless, including something that is user-alterable is a really really stupid thing to do. You want to be white-listing those files that you want to allow to be included, rather than potentially allowing access to everything on your server. Something along the lines of:
    PHP Code:
    ...
    switch(
    $_GET['id']) {
    case 
    'news':
    case 
    'about':
    case 
    'contact':
      include 
    $_GET['id'].'.php';
      break;
    default:
      include 
    'home.php';
    }
    ... 

  • #6
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It says:

    Possible solution:

    ---

    Initialize the variables via

    $<your variablename> = $_REQUEST['<your variablename>'];

    ---

    (or similar, but less general:

    $<your variablename> = $_GET['<your variablename>'];
    Which is what I have now.

    Gjay, I'll try that now.
    Last edited by stobbo; 10-29-2006 at 11:45 PM. Reason: Didn't realise new post.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •