Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-01-2008, 04:17 PM Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
I just recently uploaded my site to my server and my footer, header, and navigation do not show up. basically I have this in my header.html include file.



Can anybody shed some light?

Last edited by mrflume; 09-02-2008 at 07:22 PM..
mrflume is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-01-2008, 05:35 PM Re: Php Include problem
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
There, some light...

1) try to open each files individually, to check their path
2) you use "includes('include/xxx);", which mean that you are always at the same level in your site. This might cause you a problem.

Look at that:
Code:
ROOT
  |------ index.php
  |------ includes/
  |             |
  |             |---> nav.php
  |------ something/
                |
                |---> test.php
If you call your includes from index.php, there will be an includes folder at the same level.
But if you are in the "something" directory, the "includes" directory would be at the top most level, so it won't find it.

You can bypass this by using an absolute path, rather than a relative path.
Better yet, you can use PHP to resolve the absolute path:
PHP Code:
include($_SERVER['DOCUMENT_ROOT']."/includes/nav.php"); 
$_SERVER['DOCUMENT_ROOT'] points to your web site root folder on the server. Use this as a start, and then specify in which folder the include are to be found.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-01-2008, 05:37 PM Re: Php Include problem
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
Did your code just stop working, or did you just divide your code into includes and can't get it to work?

Try putting a forward slash before includes/:

PHP Code:
<?php include("/includes/graybar.html"?>
Not entirely sure that will help. If that doesn't work, try using an absolute path (http://yoursite.com/includes/nav.html).
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Last edited by thehuskybear; 09-01-2008 at 05:39 PM..
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Old 09-01-2008, 05:41 PM Re: Php Include problem
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
Quote:
Originally Posted by tripy View Post
You can bypass this by using an absolute path, rather than a relative path.
Better yet, you can use PHP to resolve the absolute path:
PHP Code:
include($_SERVER['DOCUMENT_ROOT']."/includes/nav.php"); 
$_SERVER['DOCUMENT_ROOT'] points to your web site root folder on the server. Use this as a start, and then specify in which folder the include are to be found.
Definitely the way to go... this will help avoid spelling errors and will make your site more portable.

First thing, which I forgot to mention, is make sure your file names are spelled correctly... I dont know how many times I spend hours trouble shooting an application only to find that I reversed two letters in a file name! lol
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Old 09-01-2008, 05:51 PM Re: Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
Ok i tried putting the forward slash and I tried the absolute path as well and they both didnt work. Basically when I view my index.php page on the web, it displays some of my background images that are actually on the index page and not includes. Everything I tried including with php is just displayed in black text where it should be on the page and just shows the contents of my includes files (div tags with the html).
mrflume is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 06:21 PM Re: Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
Quote:
include(
Quote:
$_SERVER['DOCUMENT_ROOT']."/includes/nav.php");




so I should put the code above in place of the php code I have now in index.php?
for each include file?
mrflume is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 06:22 PM Re: Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
Quote:
Code:
include(
Quote:
Code:
$_SERVER['DOCUMENT_ROOT']."/includes/nav.php");




so I should put the code above in place of the php code I have now in index.php?
for each include file?
mrflume is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 06:29 PM Re: Php Include problem
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Yes, it would resolve the level problem.
After that, if the result is not right, it's because the resulting HTML is not right.

Look at the source, and try to locate the error.
I tend to add an html comment in my includes, to locate where it starts, and where it ends.
It helps debugging the include in those cases
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-01-2008, 06:50 PM Re: Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
Hmm looking at the source on the actual live page and this is what the code reads as

I have no idea why it's doing that. Does godaddy.com support php?

Last edited by mrflume; 09-02-2008 at 07:22 PM..
mrflume is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 07:27 PM Re: Php Include problem
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
Thats strange... are you using godaddy's html editor to edit your include pages?

Perhaps if you are it is adding the head stuff:
Code:
<meta name="Generator" content="Cocoa HTML Writer">
Im sure your account supports php otherwise, nothing would show up.. your index.php would be read as text
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Old 09-01-2008, 07:36 PM Re: Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
This is what I'm seeing when I view index.php. I am using Dreamweaver not Godaddy's editor. I tried what this website suggested and it didn't work either. http://www.pro-dezign.com/php-include.html

By the way, does the fact that I made this website with a Mac have anything to do with this not working right?

Last edited by mrflume; 09-02-2008 at 07:22 PM..
mrflume is offline
Reply With Quote
View Public Profile
 
Old 09-02-2008, 01:25 AM Re: Php Include problem
Skilled Talker

Posts: 90
Name: Ed
Trades: 0
I figured this out. I made the includes in text edit on my mac and saved them with a php extension. For some reason that other text got added in there somehow and I opened each of them in dreamweaver, removed all the code and repasted just my text and it worked.
mrflume is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Php Include problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34358 seconds with 12 queries