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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Include refusing to work!

    Ok, so back when I was into the anime web community, a whole array of simple but effective sites were in place. They mainly used the PHP Include variables that would run by inputting the page to be included into the URL bar..

    For example:

    <?php include("$id.html"); ?> //This would be written where the included content was required.
    Any links would be
    <a href="index.php?id=about">About</a>
    (URL would show http://what ever.com/index.php?id=about)

    Now, I'm using that very same method i used a few years ago. Please see here: http://hiatus-wigan.co.uk/spy/index.php?id=test

    See the error?

    Warning: main(.html) [function.main]: failed to open stream: No such file or directory in C:\inetpub\vhosts\hiatus-wigan.co.uk\httpdocs\spy\index.php on line 125

    Warning: main() [function.include]: Failed opening '.html' for inclusion (include_path='.;./includes;./pear') in C:\inetpub\vhosts\hiatus-wigan.co.uk\httpdocs\spy\index.php on line 12
    I've never ripped my hair out before and don't intend to. This is such a simple task usually! Has PHP settings changed since I used this last in terms of config? ARRRGH HELP!

    Thanks in advance

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,417
    Thanks
    68
    Thanked 102 Times in 101 Posts
    It's picking a file from the C: drive instead of a website? It's possible that you can't include HTML files since they are client side language.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So what do i do? Ive tried with txt files aswell.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I presume you were relying upon register_globals setting of your server which might be OFF now. Try adding
    PHP Code:
    $id=$_GET['id']; 
    at the top of your page.

    PS: You need to filter the user inputs to prevent access to the important files in your server.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so at the top of the page i put
    <?php $id=$_GET['id']; ?>
    ?

    Im sorry its been a few years and ive never had to fart about like this! Might have to explain in moron terms, apologies.

  • #6
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    We're left guessing at this point. Can you post your PHP source code for the file in question (so we can see what is on lines 12 and 125, as well as what preceeds them)?

    That will help solve it more quickly.

    P.S. You can include *.html, *.php, or *.anythingelseyoulike - The problem is not your filetype.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #7
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    The reason it's not working is because you are saying include the value in $id.html and not $id even if the php var is $id the code you wrote is making the php parser think it's $id.html so try this.

    PHP Code:
    <?php
    # Path to the files
    $dir   "./";
    # Error filename
    $error "error.html";
    # Filename of URL id
    $file  = (!empty($_GET['id']))?"{$_GET['id']}.html":$error;
    # Blocked files
    $block = array('hidden_file1.html','hidden_file2.html');
    # Checking file and blocked files
    if(file_exists($dir.$file)&&!in_array($file,$block)) {
      
    # Requiring the file once
      
    require_once $dir.$file;
    } else {
      
    # Require the error file once
      
    require_once $dir.$error;
    }
    ?>
    If you have a php var like $id or $_GET['id'] etc you can't just write a string after it like $id.html for this to work you have to enclose the var with-in brackets like {$id} so it will then look like this {$id}.html this tells the php parser that the text enclosed between the brackets is a variable and the text outside the brackets is just standard text.

    Quote Originally Posted by myfayt
    It's picking a file from the C: drive instead of a website? It's possible that you can't include HTML files since they are client side language.
    The C: drive doesn't come into it as it might be on a server which then defines the site root as the base of all it's calls and you can require/include html files with php just because its client side doesn't mean you can't require/include the file.
    Last edited by DJCMBear; 11-30-2010 at 05:18 PM.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


  •  

    Posting Permissions

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