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 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post

    Certain file names won't 'include'

    I am having a VERY strange problem! I have a new site I am working on and have a very basic index.php:
    PHP Code:
    <?php
    include_once 'libs/config.inc.php';
    function 
    __autoload($className){
        require_once 
    'libs/classes/' $className '.class.php';
    }
    $conn = new mysql;
    if (
    $conn->conn() !== TRUE) {
        die(
    "Database connection could not be made");
    }
    $output = new tables;
        
    $output->table_id "govt";
        
    $output->table_class "display";
    $table $output->output_all('government');

    include_once 
    'libs/layout/header.inc.php';
        echo 
    $table;
    include_once 
    'libs/layout/footer.inc.php';
    ?>
    This page will not properly include the classes or the header/footer files. If I remove the attempt at including anything but the config.inc.php, I can properly display my constants from that file, so I know that is working. I can also hard code the classes into the index.php file and they work as expect OR if I change the file names to remove the .inc and .class (with exception of the appropriately functioning config.inc.php) then the page also works. I can't for the life of my figure this one out. I have tried just including the header/foot files without the class code and that does work and vice versa.

    phpMyAdmin is installed on the server, so I know that this naming convention is working there. What on earth could possibly be going on?

    EDIT: Also forgot to mention that is I use 'include_once' instead of 'require_once' for the class autoloader, I get an error message saying the class can't be found on the line tat I try to instantiate it, whereas with require_once I get a blank screen.
    Last edited by Gremlyn1; 01-13-2010 at 09:35 PM.

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    It sounds like the paths are incorrect. Do you have error reporting on?
    at the top of your file put
    PHP Code:
    error_reporting(E_ALL); 
    and see if you get any errors for it
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Maybe this is useful to you.

    I would like to share one very useful tip with include_* statements. For example we have two classes first.class.php and second.class.php both located in the same directory (./classes) and first one uses the second one. So we have:

    first.class.php
    <?php
    include_once './second.class.php';
    ...
    ?>

    also we have file which uses first.class.php:

    <?php
    include_once './classes/first.class.php';
    ...
    ?>

    if you will try to execute your script you will get error. Reason: the current directory is different and the relative path in first.class.php (./second.class.php) will be incorrect.

    Here is two possible solution I have found:

    <?php
    include_once dirname(__FILE__).'/second.class.php';
    ...
    ?>

    or

    <?php
    chdir(dirname(__FILE__));
    include_once './second.class.php';
    ...
    ?>

    Hope that tip will be useful for some other software developer
    Copied from PHP.NET
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by JAY6390 View Post
    It sounds like the paths are incorrect. Do you have error reporting on?
    at the top of your file put
    PHP Code:
    error_reporting(E_ALL); 
    and see if you get any errors for it
    I have E_ALL turned on in my php.ini file, it's weird that I wasn't getting any errors output. The file paths are definitely correct, though, because simply renaming the file works.

    Quote Originally Posted by masterofollies View Post
    Maybe this is useful to you.

    Copied from PHP.NET
    I did see that, but the only file doing any including/requiring is the index.php. The tables class extends the mysql class so it can directly access database call functions, but that wouldn't have any bearing.

    So now the weird thing... I found a snippet on a page somewhere about character encoding of the files and that setting to UTF-8 without BOM made his files work and it seems to have made mine work to... Very odd. I think it actually might be related to the MIME type of the file, not the charaset.
    Last edited by Gremlyn1; 01-13-2010 at 09:57 PM.

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    this much be work well:

    put your all inlcudes file to the same folder/directory
    than replace all to:

    <?php
    include_once 'second.class.php';
    .....
    ?>

    or

    <?php
    require './yourfoldername/second.class.php';
    .....
    ?>
    remove or add yourfoldername, or using ../ and make sure you type all correct file name

    or put your complete path/ url and all certain files name here..
    Best Regards,


  •  

    Posting Permissions

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