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
Creating virtual php includes?
Old 05-09-2009, 05:41 PM Creating virtual php includes?
Skilled Talker

Posts: 62
Name: Andrew
Trades: 0
I'm trying to create a simple server side include for my php pages so I can include my logo and footer on each page. I don't have any problems when I use an include that is relative to the document, such as:

<?php require_once('includes/logo.html'); ?>

But when I try to create an include that is relative to the site root (virtual include), I keep getting errors. Here is the code I am trying to use:

<?php virtual('/includes/logo.html'); ?>

I get an error that states:

Fatal error: Call to undefined function virtual() in site path....

I'm trying to use virtual php includes because this makes it easier when creating new pages, even when they are in another directory.

Is there a limitation to using virtual php includes? Any suggestions on what the virtual include example above should look like if this is possible? Thank you for any suggestions.
andrew99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-09-2009, 06:22 PM Re: Creating virtual php includes?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Because the path you give without a prefix / is relative to the actual script place.
If you add an / at the beginning, it means that the path will be absolute from the root of the server, not the root of your web site.

If your site is being served via apache, you have access to the absolute value of your site root folder in $_SERVER['DOCUMENT_ROOT']

So, to solve this, simply include with this:
PHP Code:
<?php 
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/logo.html'); 
?>
Quote:
Is there a limitation to using virtual php includes?
No, except sanity.
In absolute, you could put 1 line of your program in 1 file, and use include to assemble the final script, but that would be pretty insane, wouldn't it?
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 05-09-2009 at 06:23 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-09-2009, 06:22 PM Re: Creating virtual php includes?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
virtual is only supported if PHP is installed as an apache module (not CGI)
__________________

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
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Creating virtual php includes?
 

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.39573 seconds with 12 queries