Jump to content

Is there any reason why my php includes won't read my variables?


mattphilips

Recommended Posts

When you include a file, you are specifying that path to that file.

 

So if 'include.php' is in the same directory as 'index.php':

include 'include.php';

 

If 'include.php' is in a directory called 'roflcopters', then:

include 'roflcopters/include.php';

Link to comment
Share on other sites

I am doing the full path.

 

include('http://www.domain.com/files/includes/include.php');

 

What I just noticed after I posted this is that it includes the file either way. But ther variables only seem to carry over if the include is in the same or a sub directory of the index file.

 

For example:

 

With the include file in the same directory as the index file:

echo 'test: ' . $x;

 

returns: "test: 123"

 

If the include file is outside the directory of the index the same code returns:

 

"test: "

 

Link to comment
Share on other sites

I don't think that is correct behavior.  Including a file, no matter where it is, should bring all variables in that file into scope. 

 

This, however:

include('http://www.domain.com/files/includes/include.php');

 

Is not exactly best practice.  If the files are on the same server, there is no need to specify the path to the include file with a url.

Link to comment
Share on other sites

mattphilips ,

 

    Also, the home (dir) of any file you want to include must be specified in the php.ini  " include_path " directive.

 

I suspect that if you coded error_reporting['E_ALL'];  at the beginning of your script, it will tell you that the file can't be found.

 

My ini include_path statement looks like this :

 



include_path=".:/usr/local/Zend/Core/share/pear:/usr/local/Zend/www/dev:/usr/local/Zend/www/dev/include:/usr/local/Zend/www/dev/font:/usr/local/Zend/www/dev/include/lang:/usr/local/Zend/www/dev/classes:/usr/local/Zend/www/dev/javascript:/usr/local/Zend/www/dev/library:/usr/local/Zend/www/dev/WebSVN:/usr/local/Zend/www/dev/WebSVN/languages:/usr/local/Zend/www/dev/smarty:/usr/local/Zend/www/dev/smarty/libs:/usr/local/Zend/www/dev/smarty/templates:/usr/local/Zend/www/dev/smarty/template_c:"

 

Scot L. Diddle, Richmond VA

Link to comment
Share on other sites

using the path ../include.php worked.

 

However that only works for some of my files that I want to use the same include with.

 

Also... Putting the

 

<?php
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>

 

Didn't return any errors. It either works as intended or it includes the files but the variables are not set.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.