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 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cannot include my php files

    PHP Code:
    <?php
    session_start
    ();
    //include( 'views/test.php' );

    include( 'includes/config.php' );
    include( 
    'includes/db.php' );

    include( 
    'views/v_login.php' );
    ?>
    error messages:
    Code:
    Warning: include(includes/config.php): failed to open stream: No such file or directory in /home/wax/NetBeansProjects/php_login/includes/login.php on line 13
    Warning: include(): Failed opening 'includes/config.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/wax/NetBeansProjects/php_login/includes/login.php on line 13
    Warning: include(includes/db.php): failed to open stream: No such file or directory in /home/wax/NetBeansProjects/php_login/includes/login.php on line 14
    Warning: include(): Failed opening 'includes/db.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/wax/NetBeansProjects/php_login/includes/login.php on line 14
    Warning: include(views/v_login.php): failed to open stream: No such file or directory in /home/wax/NetBeansProjects/php_login/includes/login.php on line 16
    Warning: include(): Failed opening 'views/v_login.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/wax/NetBeansProjects/php_login/includes/login.php on line 16
    I'm on Ubuntu and I've configured apache to use the website in my NetBeansProject folder. The index.php works fine as well as the phpinfo() function. These includes don't. The files exist in their proper directories.

  • #2
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    This might not fix your problem, but I always shudder when I see paths that don't start with a dot or /.

    As a first step, start the path to the included file with a / if specifying an absolute path from the projects root folder or a dot if you prefer to use a relative path to the included file.

    hth

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by webdev1958 View Post
    This might not fix your problem, but I always shudder when I see paths that don't start with a dot or /.

    As a first step, start the path to the included file with a / if specifying an absolute path from the projects root folder or a dot if you prefer to use a relative path to the included file.

    hth
    Thanks, I got it to work with this:
    PHP Code:
    <?php
    /*
     * login.php
     * Log in members
     */

    //start session / load configs

    session_start();
    set_include_path('/home/wax/NetBeansProjects/php_login/');
    //include( 'views/test.php' );

    include( 'includes/config.php' );
    include( 
    'includes/db.php' );

    include( 
    'views/v_login.php' );
    ?>

  • #4
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    ok

    Then assuming the file containing your php code is in

    Code:
    '/home/wax/NetBeansProjects/php_login/'
    then in theory this should work.
    PHP Code:
    session_start(); 

    include( 
    './includes/config.php' ); 
    include( 
    './includes/db.php' ); 

    include( 
    './views/v_login.php' ); 

  • #5
    New Coder
    Join Date
    Jan 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by webdev1958 View Post
    ok

    Then assuming the file containing your php code is in

    Code:
    '/home/wax/NetBeansProjects/php_login/'
    then in theory this should work.
    PHP Code:
    session_start(); 

    include( 
    './includes/config.php' ); 
    include( 
    './includes/db.php' ); 

    include( 
    './views/v_login.php' ); 
    This didn't work. However, this did:
    PHP Code:
    <?php
    session_start
    ();
    //set_include_path('/home/wax/NetBeansProjects/php_login/');
    //include( 'views/test.php' );

    include( '/home/wax/NetBeansProjects/php_login/includes/config.php' );
    include( 
    '/home/wax/NetBeansProjects/php_login/includes/db.php' );

    include( 
    '/home/wax/NetBeansProjects/php_login/views/v_login.php' );
    ?>

  • #6
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    ok, I'm not sure which folder your file containing the php code calling the includes is in - but at least you have it sorted now

  • #7
    New Coder
    Join Date
    Jan 2009
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by webdev1958 View Post
    ok, I'm not sure which folder your file containing the php code calling the includes is in - but at least you have it sorted now
    Oh. Yep, this works, thanks.

    PHP Code:
    <?php

    //start session / load configs
    session_start();

    include( 
    './config.php' );
    include( 
    './db.php' );

    include( 
    '../views/v_login.php' );
    ?>

  • #8
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by DrWily View Post
    Oh. Yep, this works, thanks.

    PHP Code:
    <?php

    //start session / load configs
    session_start();

    include( 
    './config.php' );
    include( 
    './db.php' );

    include( 
    '../views/v_login.php' );
    ?>
    ok , which is why I originally said

    ....but I always shudder when I see paths that don't start with a dot or /.
    personally I always use relative paths, as you now have, rather than absolute paths. But that's just a personal preference.

  • Users who have thanked webdev1958 for this post:

    DrWily (08-28-2011)

  • #9
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,226
    Thanks
    10
    Thanked 269 Times in 268 Posts
    ....but I always shudder when I see paths that don't start with a dot or /.
    Just curious why you would shudder at includes/file.txt and not shudder at ./includes/file.txt - they're the same thing, aren't they? I haven't heard of the former somehow being wrong or less desirable usage before.

    Dave


  •  

    Posting Permissions

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