include won't work for some reason

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robertcode@gmail.com

    #1

    include won't work for some reason

    Hey all, I'm trying to get this include to work but I can't for some
    reason. Each file I'm trying to include is named articles.php, but the
    directories are different. So I set up the link to my include.php file
    like this

    <a href="include.p hp?directory='. $articlename.'" >'.$articletitl e.'</a>

    and on the reciving end

    <?php include '/'.$_GET["directory"].'/articles.php'; ?>

    The rest of the page comes up, but the incuded part is nowhere to be
    found.

    I'd appreciate any help anyone could offer.

    Thanks,
    RC.

  • robertcode@gmail.com

    #2
    Re: include won't work for some reason

    Forgot to mention, the hyperlink is in php, and when I change include
    to echo it comes out as it should:

    /content/articles.php

    Comment

    • Pedro Graca

      #3
      Re: include won't work for some reason

      robertcode@gmai l.com wrote:
      <?php include '/'.$_GET["directory"].'/articles.php'; ?>
      The include file is fetched from the file system.
      You are trying to fetch /<QUERYSTRING_DI RECTORY>/articles.php
      ----------------------- ^

      You can either omit the '/' (and make sure the QUERYSTRING_DIR ECTORY
      exists as a subdirectory of the one the script is running from) or
      specify the full path to the articles.php script(s).

      <?php
      $article_dir = $_GET['directory'];

      ### You will need to write the `directory_is_v alid()` function :)
      if (directory_is_v alid($article_d ir)) {
      include 'C:/Apache/htdocs/' . $_GET["directory"] . '/articles.php';
      } else {
      ### For simplicity sake, just exit with an error message
      exit('Invalid directory.');
      }
      ?>

      --
      File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

      Comment

      • Jerry Stuckle

        #4
        Re: include won't work for some reason

        robertcode@gmai l.com wrote:
        Hey all, I'm trying to get this include to work but I can't for some
        reason. Each file I'm trying to include is named articles.php, but the
        directories are different. So I set up the link to my include.php file
        like this
        >
        <a href="include.p hp?directory='. $articlename.'" >'.$articletitl e.'</a>
        >
        and on the reciving end
        >
        <?php include '/'.$_GET["directory"].'/articles.php'; ?>
        >
        The rest of the page comes up, but the incuded part is nowhere to be
        found.
        >
        I'd appreciate any help anyone could offer.
        >
        Thanks,
        RC.
        >
        What exactly does $articlename contain?

        Also, the way you're accessing it is relative to the root of the file
        system. If you want it relative to the root of the webserver, you need
        to use:

        <?php include $_SERVER['DOCUMENT_ROOT'] .
        '/'.$_GET["directory"].'/articles.php'; ?>


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Gordon Burditt

          #5
          Re: include won't work for some reason

          >Hey all, I'm trying to get this include to work but I can't for some
          >reason. Each file I'm trying to include is named articles.php, but the
          >directories are different. So I set up the link to my include.php file
          >like this
          >
          ><a href="include.p hp?directory='. $articlename.'" >'.$articletitl e.'</a>
          >
          >and on the reciving end
          >
          ><?php include '/'.$_GET["directory"].'/articles.php'; ?>
          Using include on a variable file name with unchecked user-supplied
          pieces is very dangerous, especially if it is possible for a user to
          put any files on the system in question or if the filename can be
          made remote. It's a great way to inject viruses.

          Comment

          Working...