...

View Full Version : Error when including file in php



bilischan88
11-06-2007, 02:16 AM
Warning: main(1): failed to open stream: No such file or directory in /hsphere/local/home/dezmar/netwack.com/main.php on line 2

Warning: main(1): failed to open stream: No such file or directory in /hsphere/local/home/dezmar/netwack.com/main.php on line 2

Fatal error: main(): Failed opening required '1' (include_path='.:/usr/local/lib/php:/usr/local/lib/php/PEAR:/usr/local/share/pear') in /hsphere/local/home/dezmar/netwack.com/main.php on line 2


Those are the errors that i'm getting when loading up my page. How would I fix something like this?



require_once $_SERVER['DOCUMENT_ROOT'].'/bake.php' or die();

The file that this is pointing to definitely exists.

Rappa
11-06-2007, 02:24 AM
require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. maybe just use require()?

bilischan88
11-06-2007, 03:13 AM
I've tried using all the flavors of include(include_once, require, require_once,..) and all of them give that same error.

CFMaBiSmAd
11-06-2007, 03:51 AM
Remove the or die() that is forcing a logic OR of the string - $_SERVER['DOCUMENT_ROOT'].'/bake.php' with the die() statement and supplying that as the file name to be required/included. That is where the "1" that is being mentioned in the error message is coming from.

You can probably put proper parenthesis ( ) into the statement and get it to logically do what you want, however If the require_once() statement fails, program execution stops anyway and the or die will never be executed.

bilischan88
11-06-2007, 04:35 AM
I have it now so it's just require. But when I remove the "die" all it brings up is a blank page.
I read somewhere recently that someone else tried to include a file that itself included other files and got a similar error but didn't give anymore details than that. Is that what could cause the errors?

CFMaBiSmAd
11-06-2007, 04:44 AM
Blank pages are usually caused by fatal parse errors (the previous error was a fatal runtime error.) Check your web server log for errors and/or turn on full php error reporting in your php.ini or .htaccess file (turning on full php error reporting in your code won't show fatal parse errors because the code is never executed and the code to turn on error reporting never runs.)

bilischan88
11-06-2007, 05:59 AM
For a completely different direction..
I now see some errors some I know of and have fixed and one which I don't even know how to approach


Fatal error: session_start(): Failed to initialize storage module: user (path: /tmp)

I've had no problem with sessions until now and i've made no changes to the sessions.

kehers
11-06-2007, 08:22 AM
The first error you are getting was probably due to the fact that the path to your file doesnt exist. Have you tried echoing out $_SERVER['DOCUMENT_ROOT'] and see what you have? Do you get an absolute URL (something like http://localhost/path/) for this? If that is it, then it wont work. You cant use absolute urls in your includes (be it require or whatever). The simple work around is you using the relative path, e.g ../../anotherpath/bake.php
The second problem is (probably) due to the non existence of the folder "tmp" which have been set to be the storage for the session files. Try changing the session.save_path directory in your php.ini file or use session_save_path() directly on your pages and lets see what you come up with.
Best of luck.

Inigoesdr
11-06-2007, 03:59 PM
You cant use absolute urls in your includes (be it require or whatever).

Yes you can. If the file is a server-side language it will be parsed before it's included though.

aedrin
11-06-2007, 04:00 PM
The real question is, why would you want to use absolute paths?

firepages
11-07-2007, 12:05 AM
The real question is, why would you want to use absolute paths?

because using relative paths does not always work, the initial issue here is as already noted a bad path...

post here the results of this...



<?php
$file=$_SERVER['DOCUMENT_ROOT'].'/bake.php';
if(!file_exists($file)){
echo $file .' <br />' .getcwd();
exit();
}

aedrin
11-07-2007, 03:46 PM
because using relative paths does not always work

Why would it not?

firepages
11-07-2007, 11:34 PM
page =blah.com/subdir/index.htm
link ='../another.htm' (will probably work assuming another.htm exists)

page =blah.com/subdir/index.htm/cat/title (page uses PATH_INFO)
link ='../another.htm' (link will fail)

unless blah.com/index.htm/cat/another.htm exists
also with relative url's you cant just copy and paste markup from 1 file to another since the 2nd may require fixing the link

there are of course all manner of ways around these and other potential issues, but absolute paths simply don't fail assuming a given file exists.

how you introduce absolute paths into your code is another matter and is easier or harder dependent on your framework.

aedrin
11-08-2007, 05:02 PM
blah.com/subdir/index.htm/cat/title

This is a proper link?

If your URL ever does not resolve to a real file/location, you just use the BASE tag.

firepages
11-08-2007, 11:59 PM
This is a proper link?

yes


If your URL ever does not resolve to a real file/location, you just use the BASE tag.
don't need to, I use absolute paths ;)

aedrin
11-09-2007, 03:54 PM
I can tie cats to both of my shoes, and it'll prevent me from having to buy expensive snowshoes. But is it a clean solution? I would say some disagree.

"It works" is not always a good enough reason to do something a certain way.

Inigoesdr
11-09-2007, 03:56 PM
Interesting analogy... something you want to confess? :p

aedrin
11-09-2007, 04:00 PM
RTG... Random Thought Generator. Honestly!


:P

firepages
11-09-2007, 11:41 PM
no animals were harmed during the creation of the search-engine friendly url's

which IMO is hardly a radical new or seldom used method ... unlike the cats ;)

shedokan
11-10-2007, 08:24 PM
try this:

require_once '/bake.php' or die();

Inigoesdr
11-10-2007, 08:37 PM
It's not very likely that the file is in the root of the filesystem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum