php include/require doesn't work

Hi experts.  I'm using php 5.2.6 on my test xampp/apache server.  

All of a sudden my include ("xxxx.inc") has stopped working. When I copy the content of the included file into the parent program it is fine.  Changing to require("xxxx.inc") has no effect, neither does changing from xxxx.inc to xxxx.php.

Thoroughly confused here, any help much appreciated.

Col
LVL 3
colinspursAsked:
Who is Participating?
 
Beverley PortlockCommented:
This is probably the cause. Did you use Window's "Search" to search the entire machine for files called php.ini?

Look at this

http://www.apachefriends.org/en/faq-xampp-windows.html#phpini

The path that says " .;C:/xampp/htdocs/" is probably the correct path because it includes "." which is the current directory. If your PHP installation is using "C:\WINDOWS" then it explain why your include files are not being found.

Scan the entire machine for php.ini files, don't just look in one or two places. It'll take five minutes and you'll know what you are up against.
0
 
Beverley PortlockCommented:
First thing to do is turn error checking on and look for any error messages. Add the following line just after the first <?php tag like so

<?php

ini_set('display_errors',1); error_reporting(E_ALL);


Post back any error messages.
0
 
colinspursAuthor Commented:
Thanks for responding.

Without the ini_set change, the error is:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\index1.php  on line 22
The connection to the mySQL server failed.

Because the included file has the connect info.

With the ini_set:

Notice: Undefined variable: host in C:\xampp\htdocs\index1.php  on line 23

Notice: Undefined variable: user in C:\xampp\htdocs\index1.php on line 23

Notice: Undefined variable: password in C:\xampp\htdocs\index1.php on line 23

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\index1.php on line 23
The connection to the mySQL server failed.

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Beverley PortlockCommented:
OK, since you are on windows, permissions should not be a major problem (unlike Linux) but you might want to check them by right clicking the appropriate folders and looking at the properties.

I suggest that we check the path next and make sure that the .inc file is somewhere that the include/require can actually find it. Execute

phpinfo();

and do a scan for include_path and check that the folder where your include files are kept are in the include path. Also remember that it is best to use '/' as directory separators on Windows as PHP translates then to '\' for you and it avoids the  "escaping" issues that you get with using '\'
0
 
colinspursAuthor Commented:
I think you are on the right lines.  I have corrected the path in the .ini file but it's having no effect, so presumably that means restarting apache.  Do I need to reboot my PC to do that?  (sorry, getting into basics here!).

Col
0
 
Beverley PortlockCommented:
YOu should be able to restart Apache from the XAMPP control panel, but I cannot remember how to do it. Restarting the PC is probably simplest.

Also do a scan for .ini files - there are often TWO of them. One for Apache and one for CLI usage using PHP in a non-webserver environment). Use the Windows search for php.ini and just see how many you have and make sure you edit the correct one.
0
 
Beverley PortlockCommented:
Another thing to try (should have mentioned it earlier...) when doing includes, rather than

include 'myfile.inc';

do

include './myfile.inc' ;

to enforce the relative path from the current directory. This prevents PHP from deciding how it will interpret things.
0
 
colinspursAuthor Commented:
Still the same.  From phpinfo:

Configuration File (php.ini) Path       C:\WINDOWS
Loaded Configuration File       C:\xampp\apache\bin\php.ini

Are these contradicting each other??  The php.ini I have been amending is C:\xampp\apache\bin\php.ini

There is no php.ini in c:|WINDOWS

php.ini include path:        .;C:/xampp/htdocs/
0
 
colinspursAuthor Commented:
Many thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.