...

View Full Version : Cannot include my php files



DrWily
08-28-2011, 05:52 AM
<?php
session_start();
//include( 'views/test.php' );

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

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

error messages:

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.

webdev1958
08-28-2011, 06:00 AM
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 :)

DrWily
08-28-2011, 06:12 AM
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
/*
* 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' );
?>

webdev1958
08-28-2011, 06:20 AM
ok :)

Then assuming the file containing your php code is in


'/home/wax/NetBeansProjects/php_login/'

then in theory this should work.


session_start();

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

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

DrWily
08-28-2011, 06:30 AM
ok :)

Then assuming the file containing your php code is in


'/home/wax/NetBeansProjects/php_login/'

then in theory this should work.


session_start();

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

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

This didn't work. However, this did:

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

webdev1958
08-28-2011, 06:35 AM
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 :)

DrWily
08-28-2011, 06:48 AM
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

//start session / load configs
session_start();

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

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

webdev1958
08-28-2011, 06:56 AM
Oh. Yep, this works, thanks.


<?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.

tracknut
08-28-2011, 04:47 PM
....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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum