View Full Version : PHP Include refusing to work!

11-30-2010, 01:46 PM
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

11-30-2010, 02:09 PM
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.

11-30-2010, 02:10 PM
So what do i do? Ive tried with txt files aswell.

11-30-2010, 02:23 PM
I presume you were relying upon register_globals setting of your server which might be OFF now. Try adding
$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.

11-30-2010, 02:44 PM
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.

11-30-2010, 02:53 PM
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.

11-30-2010, 05:12 PM
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.

# 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.

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.