include problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

include problem

Post 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?
Last edited by Vegan on Wed Sep 22, 2010 1:05 pm, edited 1 time in total.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
lang79james
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 10:40 pm

Re: include problem

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: include problem

Post by Vegan »

I wish to use it all over the site. My site has stewn over many levels deep in a directory tree.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: include problem

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: include problem

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
lang79james
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 10:40 pm

Re: include problem

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: include problem

Post by Vegan »

I am using Linux and the standard LAMP stack
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
lang79james
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 10:40 pm

Re: include problem

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: include problem

Post 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.
Last edited by califdon on Wed Sep 22, 2010 2:29 pm, edited 1 time in total.
Reason: I re-read your question.
lang79james
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 10:40 pm

Re: include problem

Post 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
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: include problem

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
lang79james
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 10:40 pm

Re: include problem

Post 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'; 
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: include problem

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: include problem

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: include problem

Post by Vegan »

So what can I do, grab the footer from the database?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply