PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 30th, 2012, 05:52 AM
andreea115 andreea115 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 48 andreea115 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 2 m 36 sec
Reputation Power: 2
PHP-General - Help with my php include function.

hi everyone

i really just want some ideas from everyone as to why my PHP include function is not working.

i am trying to include a page into the home page of a site.

the relevant page, for inclusion, is held in another folder on the same site. it held in the following folder :
/cms/

so, from the home page i did the following include:

PHP Code:
include('/cms/db_fns.php'); 


this should have linked to the relevant page but it does not work .

when i however did the following it worked;

PHP Code:
include('cms/db_fns.php'); 


so, i am unclear where i have gone wrong.

i need to have an absolute root so that i can use the relevant "includes" on any pages on the site, irrespective of which folder they are in.


ideally, i would like to use a web root

i.e

PHP Code:
include('http://www.thesite.com/cms/db_fns.php'); 


is there anyway to do this on a site where u cannot get access to the apache server. i.e hosting companies do not allow u access to the apache server to switch it off and on again.

can someone please advise me where i have gone wrong. thank you so much.

warm regards

Andreea

Reply With Quote
  #2  
Old November 30th, 2012, 06:58 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 26 m 54 sec
Reputation Power: 813
Hi,

please read the documentation on the include statement (it's not a function, so you don't need the parentheses).

Any path you specify for "include" refers to the file system, not the document root or something. So "/cms" would be the "cms" folder in the root directory of the server (which of course makes no sense).

What you're trying to do requires a custom php.ini with the include_path set to your "cms" directory. Relative paths will then use this directory.

However, I'm not sure if this is a good idea. I'd simply specify paths relative to the current script's directory.

Reply With Quote
  #3  
Old November 30th, 2012, 07:15 AM
andreea115 andreea115 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 48 andreea115 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 2 m 36 sec
Reputation Power: 2
Quote:
Originally Posted by Jacques1
Hi,

please read the documentation on the include statement (it's not a function, so you don't need the parentheses).

Any path you specify for "include" refers to the file system, not the document root or something. So "/cms" would be the "cms" folder in the root directory of the server (which of course makes no sense).

What you're trying to do requires a custom php.ini with the include_path set to your "cms" directory. Relative paths will then use this directory.

However, I'm not sure if this is a good idea. I'd simply specify paths relative to the current script's directory.



HI again everyone and special thanks to Jacques1 for his response.

i am a little bit confused by the answer though.

are you saying that i am not suppose to use the slash symbol i.e /

or i am not suppose to use the " "

is it possible for you or someone to give me an example of how the include should be. .

i looked at the "include documentation" but its not clear about the syntax for includes where the file is in another folder from the actual page.


warm regards

Andreea

Reply With Quote
  #4  
Old November 30th, 2012, 07:36 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 26 m 54 sec
Reputation Power: 813
Quote:
Originally Posted by andreea115
i looked at the "include documentation" but its not clear about the syntax for includes where the file is in another folder from the actual page.


This has nothing to do with a special "syntax" or something. You have to understand the difference between web paths and file system paths.

The "include" statements operates on the file system. So when you are on a Windows machine, it would take paths like "C:\\htdocs\\cms\\index.php". On a Linux machine, it would take paths like "/var/www/cms/index.php". We're talking about actual, physical paths of the operating system here.

This is completely different from web paths like "/cms/index.php" in the URL "http://www.mycoolsite.com/cms/index.php". Those are "virtual" paths that are resolved relative to the webserver's document root and don't even have to actually exist.

Again: "include" uses the file system. So when you specify the path "/cms", PHP will actually look in the root directory of your Linux/Windows installation. And I'm pretty sure there is no "cms" folder.

Reply With Quote
  #5  
Old November 30th, 2012, 07:55 AM
andreea115 andreea115 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 48 andreea115 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 2 m 36 sec
Reputation Power: 2
Quote:
Originally Posted by Jacques1
This has nothing to do with a special "syntax" or something. You have to understand the difference between web paths and file system paths.

The "include" statements operates on the file system. So when you are on a Windows machine, it would take paths like "C:\\htdocs\\cms\\index.php". On a Linux machine, it would take paths like "/var/www/cms/index.php". We're talking about actual, physical paths of the operating system here.

This is completely different from web paths like "/cms/index.php" in the URL "http://www.mycoolsite.com/cms/index.php". Those are "virtual" paths that are resolved relative to the webserver's document root and don't even have to actually exist.

Again: "include" uses the file system. So when you specify the path "/cms", PHP will actually look in the root directory of your Linux/Windows installation. And I'm pretty sure there is no "cms" folder.



thank you. that is great. i am starting to understand. but i am still not clear what i am suppose to do now.
is it possible to give an example of how i can write the path?


regards

Andreea

Reply With Quote
  #6  
Old November 30th, 2012, 08:16 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 26 m 54 sec
Reputation Power: 813
Please don't make a full quote of every reply. The text is right above your post, so no need to repeat it.

Quote:
Originally Posted by andreea115
is it possible to give an example of how i can write the path?


I said that in my first reply. If you put your "cms" directory into the include_path (read the documentation), you can refer to it with relative paths. For example, if you say
PHP Code:
include 'scripts/db.php'

then "scripts/db.php" will be looked up in your "cms" directory (among others).

If you have problems understanding how paths in general work, google for "file path".

Reply With Quote
  #7  
Old December 1st, 2012, 05:29 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,947 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 37 m 24 sec
Reputation Power: 7053
Most PHP software handles this by defining a constant that references the root of the application. For example, something like:
PHP Code:
 define('ROOT''/var/www/html/'); 


Then throughout the application whenever they need to include something, they use the ROOT constant to do it:
PHP Code:
include(ROOT 'libraries/includeme.php'); 
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Help with my php include function.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap