Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Error when including file in php

    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?

    PHP Code:
    require_once $_SERVER['DOCUMENT_ROOT'].'/bake.php' or die(); 
    The file that this is pointing to definitely exists.

  • #2
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts
    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()?

  • Users who have thanked Rappa for this post:

    matak (11-07-2007)

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've tried using all the flavors of include(include_once, require, require_once,..) and all of them give that same error.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    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.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    New Coder
    Join Date
    Nov 2007
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Location
    Nigeria
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by kehers View Post
    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.

  • #10
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    The real question is, why would you want to use absolute paths?

  • #11
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Quote Originally Posted by aedrin View Post
    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 Code:
    <?php
    $file
    =$_SERVER['DOCUMENT_ROOT'].'/bake.php';
    if(!
    file_exists($file)){
       echo 
    $file .' <br />' .getcwd();
       exit();
    }
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #12
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    because using relative paths does not always work
    Why would it not?

  • #13
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #14
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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.

  • #15
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Quote Originally Posted by aedrin View Post
    This is a proper link?
    yes
    Quote Originally Posted by aedrin View Post
    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •