Page 1 of 3

include problem

Posted: Wed Sep 22, 2010 12:31 pm
by Vegan
On my home page I have been exploring the use of the global php footer

so if I use

<?php include ('global_footer.php'); ?>

it works, but if I use my full domain, it does not, thoughts?

Re: include problem

Posted: Wed Sep 22, 2010 12:42 pm
by lang79james
If that works then why change it. Or do you want to use it on many pages.

Well for me I got one that is in a date folder and it seems to work well for me.
Some time I have to give the file location like
/var/www/data/####.php
But I can only do this because I am hosting it from home.

Re: include problem

Posted: Wed Sep 22, 2010 12:48 pm
by Vegan
I wish to use it all over the site. My site has stewn over many levels deep in a directory tree.

Re: include problem

Posted: Wed Sep 22, 2010 12:58 pm
by califdon
I believe that PHP include is intended only for files on the same server that is running the PHP script, so when you put a domain name in there, it isn't a valid path on the server.

Re: include problem

Posted: Wed Sep 22, 2010 1:05 pm
by Vegan
What can I use to get it used generally?

I noticed when I used ../global_footer.php that the PayPal image did not render when it worked fine on the home page.

Sure seems to be clumsy

Re: include problem

Posted: Wed Sep 22, 2010 1:58 pm
by lang79james
I remember using the include command to open a file from anther server. I think i did for giggles, but like I said I can do that because I am hosting it . Maybe you can create folder on all off your servers that link to one folder. Just a thought, I forget what it is called though. I know In ISS when i was playing with ASP.NET i was able to do that.

Re: include problem

Posted: Wed Sep 22, 2010 2:03 pm
by Vegan
I am using Linux and the standard LAMP stack

Re: include problem

Posted: Wed Sep 22, 2010 2:20 pm
by lang79james
well if you hosting it your self then why not use the file path.

Code: Select all

include '/var/www/footer.php';
I know for some stupid reason i have to do this with some of my code to get it working right.
for me i got pages in root and some others in sub dir's. and when I use the file path it works like a champ.

Re: include problem

Posted: Wed Sep 22, 2010 2:23 pm
by califdon
I don't see anything in the documentation that leads me to believe that include() can be used to include a file that's not on the same physical server, but I'm certainly not an expert in this area. You might look into curl, which is the command that is intended for accessing external URLs.

Edit: Oh wait, you're not talking about remote servers? Then I don't see what your problem is. If you're trying to include a file that's stored on the same server, and particularly if it's working on one page, then you must just have an error in your code, maybe a simple typo. We can't tell unless you show us the code that DOES work and the code that DOESN'T work.

Re: include problem

Posted: Wed Sep 22, 2010 2:33 pm
by lang79james
I got the impression all of his files are on the same computer
example

|root
|-folder 1
|-- folder 1.1
|-- folder 1.2
|--- folder 1.2.1
|--- folder 1.2.2
|-folder 2
|-folder 3
|--folder 3.1
|---folder 3.1.1
|----folder 3.1.1.1
|-----folder 3.1.1.1.1

and so one

Re: include problem

Posted: Wed Sep 22, 2010 2:38 pm
by Vegan
<?php include('global_footer.php'); ?> // works

<?php include('http://wwww.contract-developer.tk/global_footer.php'); ?> // does not work

<?php include('/global_footer.php'); ?> // does not work

Re: include problem

Posted: Wed Sep 22, 2010 2:55 pm
by lang79james
Vegan wrote:<?php include('global_footer.php'); ?> // works

<?php include('http://wwww.contract-developer.tk/global_footer.php'); ?> // does not work

<?php include('/global_footer.php'); ?> // does not work
what about

Code: Select all

include './global_footer.php'; 

Re: include problem

Posted: Wed Sep 22, 2010 3:11 pm
by Vegan
That one seems to work, thanks for the suggestion.

The putative footer is located at the root of the site, so all of the documents are relative to that document root.

Re: include problem

Posted: Wed Sep 22, 2010 3:31 pm
by califdon
Vegan wrote:<?php include('global_footer.php'); ?> // works

<?php include('http://wwww.contract-developer.tk/global_footer.php'); ?> // does not work

<?php include('/global_footer.php'); ?> // does not work
That's what I said. "http://" says that it is looking for a website using http protocol--it would send a request to the DNS system to obtain an IP address, etc. That's not what include() does. It uses normal file system paths to find a file on the same server. The last one should work if the file is located directly in the Document Root of that server. The first one works because it is in the same directory as the script that's calling it. Using "./" works because it means the same thing: "this directory", but it's not required.

Re: include problem

Posted: Wed Sep 22, 2010 4:02 pm
by Vegan
So what can I do, grab the footer from the database?