Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file_get_content works but include() and require dont work

Status
Not open for further replies.

spavkov

Programmer
Jun 16, 2004
26
Hi Guys,

im puzzled:

i need to install one php4 application on php 4.4.1 server
(running as Apache 1.3.34 module)

my doc root is this:
["DOCUMENT_ROOT"]=> "/home/someuser/public_html"
and my app is in the document root in subdir /sb/
so it is in "/home/someuser/public_html/sb/"

in script home.php i have this problem:
this code WORKS:
$a=file_get_contents("/home/someuser/public_html/sb/config.php");

and this code DOES NOT WORK:
include_once("/home/someuser/public_html/sb/config.php");
this also DO NOT work:
require_once("/home/someuser/public_html/sb/config.php");
include("/home/someuser/public_html/sb/config.php");
require("/home/someuser/public_html/sb/config.php");

when i use the include() and require() the script just frezes and does not output anything to the browser...

any ideas...?

im clueless....

please help me out on this...

 
Are those functions called before everything else (including the <html> tag)?
 
Yes, this code is executed first before everything else, even before <html> tag.

why?

 
one more thing:

i tried:

require_once("config.php");

and it works!

but when i try:
require_once("/home/someuser/public_html/sb/config.php");
it fails!

and im 100% sure that "/home/someuser/public_html/sb/"
is the right path... its not problem there...
im sure its in the way how Apache or PHP are set up...

anyone?

 
After you perform:

[tt]$a=file_get_contents("/home/someuser/public_html/sb/config.php");[/tt]

what does your working script do with the value in $a?


What does config.php look like?




Want the best answers? Ask the best questions! TANSTAAFL!
 
i dont do anything with value in $a after the

$a=file_get_contents("/home/someuser/public_html/sb/config.php");

i just did this to see if its working...
and it does...

config.php is just a script with one configuration class that has all the configration data for my application...

but this has nothing to do with the reason why script cannot access it via include() or require()...

i do a var_dump($_SERVER)
and i get: (among other stuff):
["DOCUMENT_ROOT"]=> string(26) "/home/someuser/public_html"

and my scripts are in "sb" subdir in "public_html"

so, i think that
require_once("/home/someuser/public_html/sb/config.php");
should work if config.php is in sb subdir of public_html ??

but it does not work...





 
You're using an absolute filesystem path in your require_once() invocation:

require_once("[red]/home/someuser/public_html/sb/config.php[/red]");

so it doesn't matter where the files are relative to one another.

You said in your initial post, "when i use the include() and require() the script just frezes and does not output anything to the browser..." do you mean that the connection between the browser and server never completes?


What are the values for "display_errors" and "error_reporting" in your php.ini? It could be PHP is being prevented from displaying an error.



Want the best answers? Ask the best questions! TANSTAAFL!
 
error reporting is switched on and set to error_reporting(E_ALL);

i tried these scripts on another server that has the same version of php and all works fine...

im 100% sure its PHP or APACHE configuration problem...

just cannot figure out what it is...

thanks,
Slobo

 
>>config.php:<<

<?php
set_time_limit(0);
ignore_user_abort(true);
//
// config.php
//
class cfg_class
{
var $DEBUG;
var $LOCAL;
var $appname;
var $dirroot;
var $approot;
var $includedir;
var $uploadsdir;
var $projectsdir;
var $mprojectsdir;
var $kwdir;
var $logsdir;
var $tpldir;
var $repositorydir;
var $zipdir;
var $peardir;
var $imgdir;
var $sqldir;
var $tmpdir;

var $db_host;
var $db_user;
var $db_pass;
var $db_name;

var $webserver;
} // cfg_class

/* @var cfg_class */
$CFG =& new cfg_class();

$CFG->DEBUG = false;

$CFG->LOCAL = false;

$CFG->ftppassive = true;
$CFG->DDEBUG = true;

$CFG->webserver = $_SERVER['SERVER_NAME'];
$CFG->dirroot = dirname(__FILE__)."/";
$CFG->approot = $CFG->dirroot;
$CFG->tmpdir = $CFG->approot."tmp/";
$CFG->sqldir = $CFG->approot."sql/";
$CFG->includedir = $CFG->approot."include/";
$CFG->uploadsdir = $CFG->approot."uploads/";
$CFG->projectsdir = $CFG->approot."projects/";
$CFG->mprojectsdir = $CFG->approot."mprojects/";
$CFG->kwdir = $CFG->approot."kw/";
$CFG->logsdir = $CFG->approot."logs/";
$CFG->tpldir = $CFG->approot."tpl2/";
$CFG->repositorydir = $CFG->approot."repository/";
$CFG->zipdir = $CFG->approot."zip/";
$CFG->peardir = $CFG->approot."pear/";
$CFG->imgdir = $CFG->approot."img/";

$CFG->db_host = "localhost";


?>
-----------------------------------------
>>home.php:<<

<?php
require_once(dirname(__FILE__)."/config.php");
print("a");
require_once($CFG->includedir."security_class.php");
print("b");
require_once($CFG->includedir."tt_class.php");
print("c");

print("I made it here !!!");

?>
etc etc

the code is fine i think...
print lines are just to see what is executed...

both files are in the same dir...

something else is the issue here...

anyway, im posting it...

let me know if you have any ideas...

tnx

 
in windows i dont think that the notation "/somedir/someotherdir/filename.php" is necessarily an absolute path. is the OP using windows or *nix or someother OS?
 
it was the problem in the server apache and php installation...

hosting company rebuilt the apache and php and all started to work...

thanks to all guys who tried to help...



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top