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.
Results 1 to 11 of 11

Thread: Require Issue

  1. #1
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Require Issue

    Hello

    I have an issue with a new website which I installed. My problem is with the "require ("page")" calling code which is causing a problem I have never seen before.

    Discription; To access the user pages (index.php) the require code needs to be set to ("index.php") but to access my Admin pages I need to change this require code to ("../index.php") for it to work.

    I have tried placing the full URL there but that just stops everything from working. I also tried putting both calling codes there but that also doesn't work.

    Does anyone have any idea on how I can fix this issue please as going to my files constantly to change this from one to the other is just not only annoying but also closes the website down when I am accessing the Admin.

    Cheers

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    You need to show your code for us to see whats going on.

    Secondly require doesn't work with URLs so you'd best use a file system path instead. If you want to get something via a url use file_get_contents() instead (note that it won't get php code though - because it will run on that remote system as normal).
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Hello

    My code is
    PHP Code:
    <?
    require ("includes/db.php");
    $get_globals mysql_query("SELECT * FROM settings LIMIT 0,1")or die(mysql_error());
    ?>
    This is the require which is in my config_global.php file which is used to call the website up.


    The db file just has my database details and that is it.

    The error message I get when trying to access the Admin is

    Code:
    Warning: require(includes/db.php) [function.require]: failed to open stream: No such file or directory in /home/MySite/public_html/MySite/admin/conf_global.php on line 3
    
    Warning: require(includes/db.php) [function.require]: failed to open stream: No such file or directory in /home/MySite/public_html/MySite/admin/conf_global.php on line 3
    
    Fatal error: require() [function.require]: Failed opening required 'includes/db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/MySite/public_html/MySite/admin/conf_global.php on line 3
    Line 3 is the require field code line. As mentioned earlier when I add (../) I then can access the Admin panel but the website shows this message instead.

    Cheers
    Last edited by phil1ooo; 05-27-2011 at 10:44 AM.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by phil1ooo View Post
    Discription; To access the user pages (index.php) the require code needs to be set to ("index.php") but to access my Admin pages I need to change this require code to ("../index.php") for it to work.
    Please show THAT code. Not something irrelevant.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Use / first. If the full path to the file is www.mysite.com/includes/db.php put the path to
    PHP Code:
    require("/includes/db.php"); 
    If the full path to the file is www.mysite.com/MySite/includes/db.php put the path to
    PHP Code:
    require("/MySite/includes/db.php"); 

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Do not use / first. That is useful in an HTML format as it resolves to DNS point, / in PHP will resolve to filesystem root. It is mostly unlikely that the system has a /includes on it. In other words, the full path to the file may be something like /user/yoursite/public_html/includes/file.php.

    The problem is simple, but not enough information has been provided. The error indicates that no file exists at this location (not a privilege problem as the error would indicate its not able to open the file for reading).
    Check your paths again. Also note that PHP will always resolve paths from the directory of the currently executing script (when used through a web service; CLI differs from this), so including a file which includes another file will resolve to different locations than intended. Using cwd() and chdir() or absolute paths (either explicit or variable generated) will solve that issue.

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try the absolute path as below.
    PHP Code:
    require ($_SERVER['DOCUMENT_ROOT']."/includes/db.php"); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    phil1ooo (05-27-2011)

  • #8
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Try the absolute path as below.
    PHP Code:
    require ($_SERVER['DOCUMENT_ROOT']."/includes/db.php"); 

    That worked and solved the problem.

    thank you very much for your help.

  • #9
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Please show THAT code. Not something irrelevant.
    It was that code as it was shown here. Not suppling the correct info wounldn't get me very far now and also waste good peoples time.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    You'd be surprised how many people do show irrelevant code and i could see nothing there that referred to your main or admin page that you started off telling us about.

    Quote Originally Posted by phil1ooo View Post
    Hello
    Discription; To access the user pages (index.php) the require code needs to be set to ("index.php") but to access my Admin pages I need to change this require code to ("../index.php") for it to work.
    You are quite clearly showing index.php. What you were having a problem with was including your database driver file - something totally different.

    If you're having a problem including your DB driver then say just that. No need to say about admin and main pages being used in require_once() as that only confuses the matter.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    phil1ooo (05-27-2011)

  • #11
    New Coder
    Join Date
    Dec 2009
    Location
    Australia
    Posts
    41
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    You'd be surprised how many people do show irrelevant code and i could see nothing there that referred to your main or admin page that you started off telling us about.



    You are quite clearly showing index.php. What you were having a problem with was including your database driver file - something totally different.

    If you're having a problem including your DB driver then say just that. No need to say about admin and main pages being used in require_once() as that only confuses the matter.
    The problem had to do with the way the file was being called, not the bd file it's self. I'm pretty sure I mentioned it was a calling code issue and not a db issue.

    Anyway the problem was fixed using "abduraooft" suggestion as I have tried them all as they where suggested to me.

    Thank You. This topic is now CLOSED.


  •  

    Posting Permissions

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