Php Include not working

First off thanks for reading this. I am very new to using php so my question may sound like a “Duh” to the ones that know php. Any help you can provide is greatly appreciated.

I want to start using php to simplify my web design for headers and such. I would rather change 1 file instead of 100.

The php file I want to use is in the main directory along with all the other html files using it.

I have tried using the following:

<?php include("skyscraper.php"); ?> - didn't work <?php include("http://(domain)/header.php"); ?> - didn't work

I also tried the above with single quotes instead of double. - didn’t work

I have also tried:

<?php include($_SERVER['DOCUMENT_ROOT']."skyscraper.php"); ?> - didn't work

I did see something about using /home/name/domain/file.php but was not exactly sure how to employ it. Would “home” be the dreamhost server? Is name my account name?

There is probably something very simple that I am missing. When I setup my host I use the default settings. I have not changed anything in my folder permissions, or .htaccess file. I am not trying anything fancy, but just want to use php to call images and possibly some scripts. Right now I am just testing things trying to get them to work.



The problem isn’t in your technique, but in your files. By default, files with a .html extension aren’t checked for anything that needs to be processed by another scripting engine, IE: PHP. Instead, they’re just served as is with the Apache webserver. The easiest thing for you to do here, unless you want to start messing with .htaccess files, is to just rename your HTML files to PHP ones and you’re good.

Yes, I have an opinion.

Get a minimum 50% off with the “haveadreamyday” promo code, and… have a dreamy day. Original, no?

What will work depends on where your file is that you want to include.

/home/Your_user_name/ puts you in the directory where your folders are. That path can be adjusted to work no matter where your file is.

The $_SERVER[‘DOCUMENT_ROOT’] . ‘/filename.ext’ can work if the file is in your folder. If it’s in something like / you would need to include the rest of the path after your folder before the file name. Document_root won’t work if it’s in your user directory–only the directory, since that is the document root.

Make sense?

If your file is in your folder, then putting a / before the file name would probably fix your document_root example.

The advantage to using a variable like document_root would be that if you were to switch hosts, it should still work without changing anything, making it more portable.

:stuck_out_tongue: Save up to $96 at Dreamhost with ALMOST97 promo code (I get $1).
Or save $97 with THEFULL97.

If you’re going to use DOCUMENT_ROOT, you need to add a slash after it:

<?php include($_SERVER['DOCUMENT_ROOT']."/skyscraper.php"); ?>

But your other attempt should have worked if the file is in your directory:

<?php include("skyscraper.php"); ?>

So, how do you know it’s not working?


An example of how I use includes in my file is:


<?php # $includes_path = "/home/myaccountname/"; // here I set my path incase I want to change it later #file with functions in it. include($includes_path . ""); ?>


Try that - or some variation of it. this is pretty much how I do all of my includes.



Silly question, but did you remember to surround the dynamic contents of included php file with their own php tags? When I used an include, but didn’t use php tags in the included file, it dumped the code exactly as in the document, without processing it. Other scripting languages don’t all have the same requirement. Do you see anything when you view the source? I’d surround the include line with some debugging comments to make sure something is happening.

BC Tech
Team Shocker

Thanks to everyone who gave me some good advice. I ended up adding AddType application/x-httpd-php html to the htaccess file because it was easier to change 1 file than many others.

Ref PHP tags: Problem exactly as described - solution exactly as described. Thank you.