TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-24-2008, 09:36 AM   #1 (permalink)
The Visitor
 
Join Date: Jul 2008
Posts: 4
Thanks: 1
ncorpse is on a distinguished road
Default require problem with absolut paths

Hi everyone

I'm working on a small php application that stores adresses in a mysql database. I'm using a class for printing HTML code.
So I need to include several files in several files
the problem is, that i cannot use absolut paths with require or include.
I tried to define a constant and use it like a document root.
PHP Code:
//define
define('DOCUMENT_ROOT','/var/www/tmp/');
//usage
require(".DOCUMENT_ROOT.".'dir2'); 
Can anyone show me off how I should manage my includes in a project?

Sry for my crappy english

ncorpse
ncorpse is offline  
Reply With Quote
Old 07-24-2008, 09:38 AM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by ncorpse View Post
Hi everyone

I'm working on a small php application that stores adresses in a mysql database. I'm using a class for printing HTML code.
So I need to include several files in several files
the problem is, that i cannot use absolut paths with require or include.
I tried to define a constant and use it like a document root.
PHP Code:
//define
define('DOCUMENT_ROOT','/var/www/tmp/');
//usage
require(".DOCUMENT_ROOT.".'dir2'); 
Can anyone show me off how I should manage my includes in a project?

Sry for my crappy english

ncorpse
try
PHP Code:
require(DOCUMENT_ROOT.'dir2'); 
DOCUMENT_ROOT without the quotes.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 07-24-2008, 09:43 AM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

By the way, you cant require directories. you should only use require/include for php files.

Now if you want to set an include path, just do this
PHP Code:

set_include_path
('dir2');
require 
'myfile.php'
This will only use require/include to get from the include path dir2, it's limited till you change it back or change it to something else.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 07-24-2008, 10:11 AM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

If you need to require a whole directory of files, and I mean *all* the files in that directory, you could do something akin to this:

PHP Code:
    foreach (glob(DOCUMENT_ROOT.'/*.php') as $szFilename)
    {
        require 
$szFilename;
    } 
...assuming that they have the .php extension for that example.
-m
delayedinsanity is offline  
Reply With Quote
Old 07-24-2008, 10:24 AM   #5 (permalink)
The Visitor
 
Join Date: Jul 2008
Posts: 4
Thanks: 1
ncorpse is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post
try
PHP Code:
require(DOCUMENT_ROOT.'dir2'); 
DOCUMENT_ROOT without the quotes.
that works!

No I'm not looking for including a whole directory of files
How can i use this construct inside of this?
PHP Code:
echo "<link rel='stylesheet' type='text/css'  href='./inc/css/stylesheet.css'>\n"
Thank you for your help guys

ncorpse
ncorpse is offline  
Reply With Quote
Old 07-24-2008, 01:32 PM   #6 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default

Code:

<?php
//define 
define('DOCROOT', '/var/www/'); 
//usage 
Echo '<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">\n";  
something like that.... will change your href="" to "/var/www/inc/css/stylesheet.css"


__________________
"Knowledge is power. Abuse it."~Evulness
My portfolio: www.evularts.com
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Old 07-25-2008, 09:48 AM   #7 (permalink)
The Visitor
 
Join Date: Jul 2008
Posts: 4
Thanks: 1
ncorpse is on a distinguished road
Default

Quote:
Originally Posted by Evulness View Post
Code:

<?php
//define 
define('DOCROOT', '/var/www/'); 
//usage 
Echo '<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">\n";  
something like that.... will change your href="" to "/var/www/inc/css/stylesheet.css"


I tried that out it doesn't work.
PHP Code:
define('DOCROOT','/var/www/patric/Adressverwaltung/');
...
echo 
'<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">'."\n"
It seems that it is not working when i use an absolut path. when i use ./.../ instead it works fine.
Do I need to do something with the php include paths?
ncorpse is offline  
Reply With Quote
Old 07-25-2008, 11:23 AM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by ncorpse View Post
I tried that out it doesn't work.
PHP Code:
define('DOCROOT','/var/www/patric/Adressverwaltung/');
...
echo 
'<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">'."\n"
It seems that it is not working when i use an absolut path. when i use ./.../ instead it works fine.
Do I need to do something with the php include paths?
I don't think you can use path in href, just do the url base.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
The Following User Says Thank You to Orc For This Useful Post:
ncorpse (07-25-2008)
Old 07-25-2008, 11:30 AM   #9 (permalink)
The Visitor
 
Join Date: Jul 2008
Posts: 4
Thanks: 1
ncorpse is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post
I don't think you can use path in href, just do the url base.
Dammed! You are right mate.
Now it's working
ncorpse is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:13 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design