Jump to content

[SOLVED] A question about include..


Rommeo

Recommended Posts

Hi

 

There is a small script which i have to add in every php files. I m using "include" for to do this. But my problem is about the link of the file.

 

my document tree is like this :

apage
      apageWhichpageInfoIncluded.php
page
      pageinfo.php
newcode
      code.php

I wanna include code.php to pageinfo.php

 

Let me explain clearly ;

<?php include('/newcode/code.php');  ?>

This does not work. I wanted it to reach that directory over the main directory ( like links ) But it's trying to find the code.php in /page/newcode/code.php which i dont want, so as a result of this. It does not work.

<?php include('../newcode/code.php');  ?> 

This works, but when i include pageinfo from another page, this does not work anymore.

<?php include('http://www.mysite.com/newcode/code.php');  ?> 

This also works but at this time, there are some problems about the sessions.

 

how can i solve this problem ? I ll be glad if anyone can help.

Thanx in advance.

 

 

Link to comment
https://forums.phpfreaks.com/topic/120693-solved-a-question-about-include/
Share on other sites

For code example 1, a leading slash in a file system path refers to the root of the current disk.

 

For code example 2, relative file system paths (edit: starting with ./ or ../) are relative to the current working directory, which is that of the main script (unless you want to execute a statement to change the current working directory before the include and then changed it back after the include.)

 

For code example 3, using a URL/HTTP request causes the included file to be parsed separately and you only receive any content that is output by that script.

 

The solution is to form an absolute file system path using -

 

include($_SERVER['DOCUMENT_ROOT'] . '/newcode/code.php');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.