me_digvijay
me_digvijay

Reputation: 5502

PHP include and require not working in ubuntu even after setting the include_path

Below is my include path as shown by phpinfo()

include_path    .:/usr/share/php:/usr/share/pear:/var/www/html/WebPHP

There is a page in /var/www/html/WebPHP/frags dir that I want to include in my index.php.

But nothing works.

What I am doing wrong?

Edit

    <?php
        set_include_path("/var/www/html/WebPHP/frags");
        ini_set('include_path', '/var/www/html/WebPHP/frags')
        include 'frags/GuestHeader.php';
        echo phpinfo();
    ?>

Upvotes: 0

Views: 1621

Answers (1)

Lovau
Lovau

Reputation: 537

If you only want to include one specific file, you should add in your index.php file :

require_once '/path/to/your/file.php'; 

However, if your really want to include the whole directory, you can do :

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/your/directory');

Edit : if it still doesn't work, you can do something like :

foreach (glob("/your/directory/*.php") as $filename) {
    require_once $filename;
}

Upvotes: 1

Related Questions