Web Hosting Talk







View Full Version : including a php file gives me an error. Not when include() through HTTP


Domenico
03-26-2002, 05:40 PM
Hi all!

When I try to include a php file like this:
<?
require "file.php";
?>
I get this error:
Fatal error: Failed opening required file.php'
(include_path='.:/usr/share/php') in /home/test/public_html/file.php on line 1


But when I do it like this:
<?
require "http://mydomain.com/file.php";
?>
it works!

Why is this? I can't figure out why because on some clients it does work both ways.
What is configured wrong here?

Thank you,
Domenico

MGCJerry
03-26-2002, 06:53 PM
<?
require "file.php";
?>

Not that I'm, a php expert, but try this...

<?
require ('file.php');
?>

Well... it works fine for me.... :)

hope this helps a little....

Shyne
03-26-2002, 07:31 PM
Check your php.ini file and make sure that "include_path" has no entry next to it.

Domenico
03-26-2002, 07:32 PM
Nope, I allready tried that one :(
It gives me the same error.

Anyone else?

Domenico
03-26-2002, 07:40 PM
Before there was .:/usr/share/php behind it but I removed it and restarted apache and now the error is:

Fatal error: Failed opening required 'd_projects.php?show=10' (include_path='') in /home/test/public_html/file.php on line 2

:(

kunal
03-27-2002, 03:53 AM
um... are you sure the file exists in the same dir as the script??

Domenico
03-27-2002, 05:16 AM
Yes, it's in the same dir.

Domenico
03-27-2002, 05:37 AM
Let me rephrase my problem because I forgot to mention something.

What I want to use but doesn't work is:
<?
require "file.php?show=10";
?>

This works now:
<?
require "file.php";
?>

So why is this then?

jamesl
03-27-2002, 06:02 AM
Hi,

You cannot include/require a file with any parameters passed to it directly as php looks for a file called "file.php?show=10" rather than just "file.php".

If show is not already defined in your script change it to the following:

<?
$show=10;
require "file.php";
?>

And it will be included correctly as file.php can see the variable as it is already defined in the script, note this only works for direct includes and not using includes via http:// for which you should use:

<?
require "http://mydomain.com/file.php?show=10";
?>

HTH

Domenico
03-27-2002, 06:10 AM
Thanks for telling Jamesl!

I thought of this but didn't tried it yet, stupid me :bawling:

Anyways, this is what the manual says:
- To include the top downloaders, sorted by number of reviews and rating (greatest to least), insert this where you would like the top downloaders to appear: <? require "d_top.php?show=xx"; ?> Replace "xx" with the number of top "downloaders" to display.

hehehe, someone has to go back to school then
:D