PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Include problems
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Include problems

Réponse
 
LinkBack Outils de la discussion
Vieux 12/04/2008, 07h28   #1
GoWtHaM NaRiSiPaLli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Include problems

Hi PHP Experts,

I am writing a wrapper over some existing code and when I hoped that I
almost successfully completed it, I ran into the wall.

The wrapper file is in /var/www/sites/project/ as xyz.php and the file
includes some of the files from various paths.
Starting with
==============
// Importing Init.php for initializing the libraries
include_once("checkout/controller/Init.php");

and this Init.php in /var/www/sites/project/checkout/controller loads the
configuration file and code is as below.

============================================
if(file_exists("../common/config.ini")) {
$configData = parse_ini_file("../common/config.ini");
} else {
$configData = false;
}
if (!$configData) {
die("An error occurred while trying to get ".
"confidential config data. Please ensure that the ".
"pathname to this file in Init.php ".
"is correct.");
}
============================================

This config.php file is in /var/www/sites/project/common/ but there is some
messup in the path and its not setting to the right path as it must looking
for the file with include path set to /var/www/sites/project/ rather
/var/www/sites/project/checkout(it works if I keep the xyz.php file in
checkout folder. But I want this file to be in parent folder for various
other reasons and I cant figure out for nuts how to make this path thing
work.

Thanks,
Gowtham.N

  Réponse avec citation
Vieux 13/04/2008, 04h06   #2
Bojan Tesanovic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Include problems


On Apr 12, 2008, at 8:28 AM, GoWtHaM NaRiSiPaLli wrote:

> if(file_exists("../common/config.ini")) {
> $configData = parse_ini_file("../common/config.ini");
> } else {



Try changing above code so it reads

if(file_exists("common/config.ini")) {
$configData = parse_ini_file("common/config.ini");
} else {


As the xyz.php is in

/var/www/sites/project/ folder , and that is the starting path of
the script

so any script that needs to include
/var/www/sites/project/common/someFile.php
you need to specify relative path to '/var/www/sites/project/' which
is 'common/someFile.php'

this should work unless some of included files uses 'chdir' function
that changes current directory



Igor Jocic
http://www.carster.us/ Used Car Classifieds





  Réponse avec citation
Vieux 14/04/2008, 19h15   #3
Daniel Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Include problems

On Sat, Apr 12, 2008 at 11:06 PM, Bojan Tesanovic <btesanovic@gmail.com> wrote:
>
> On Apr 12, 2008, at 8:28 AM, GoWtHaM NaRiSiPaLli wrote:
>
>
> > if(file_exists("../common/config.ini")) {
> > $configData = parse_ini_file("../common/config.ini");
> > } else {
> >

>
>
> Try changing above code so it reads
>
>
> if(file_exists("common/config.ini")) {
> $configData = parse_ini_file("common/config.ini");
> } else {


In your primary file, you could also consider adding:

<?php
$base_path = dirname(__FILE__);
?>

And then, all includes from within that file would be included as such:

<?php
include($base_path.'/common/config.ini');
?>

Finally, on a different note, it may not be in your best interest
to keep a .ini extension on a configuration file, since this is
generally readable on the web.

--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h04.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12174 seconds with 11 queries