SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Include problem

    I am trying to set up a page in my site so that I can put article.php?id=filename and include an article in the layout.

    I am really new at php and this is the code I'm trying to use:

    Code:
    <?php include (articles/'echo "$_GET['id']"'); ?>
    But it gives me a parse error. How can I fix this?

  2. #2
    SitePoint Addict devil cat's Avatar
    Join Date
    Apr 2003
    Location
    Reno
    Posts
    344
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be more like:

    PHP Code:
    <?php include( "articles/" $_GET['id'] ); ?>
    I hope you do some serious validation on that value before depending on it though.

  3. #3
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about:
    PHP Code:
    <?php
    $article 
    preg_replace('/[^a-zA-Z0-9\_]/'''$_GET['id']);
    include( 
    "articles/{$article}.php" ); // or .html
    ?>
    Christopher

  4. #4
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or:
    PHP Code:
    <?php
    $pages 
    = array("page1.php""page2.php""page3.php");
    if 
    in_array($_GET['id'], $pages)
    {
    include(
    "articles/" $_GET['id']);
    }
    else
    {
    echo 
    'Hacking Attempt';
    }
    ?>


Bookmarks

Posting Permissions

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