Web Analytics Made Easy -
StatCounter Cannot include my php files - CodingForum

Announcement

Collapse
No announcement yet.

Cannot include my php files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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

    Comment


    • #3
      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' );
      ?>

      Comment


      • #4
        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' ); 

        Comment


        • #5
          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' );
          ?>

          Comment


          • #6
            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

            Comment


            • #7
              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' );
              ?>

              Comment


              • #8
                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.

                Comment


                • #9
                  ....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

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎