Dear all Plzz help me

I am stuck with PHP include function.

I have given the include path in php.ini file as

include_path="C\PHP_includes

In PHP_include folder i have 3 files menu.inc which has html code, menu.css that has all the styles and menu.js that has certain functions.

i have a folder in my htdocs of apache called isquareit that has a file called index.php which includes menu.inc. This works fine it automatically includes all the stylesheets as well as javascript.

Then I have a folder inside isquareit named SOIT which has a file called soit.php. The Problem comes when i try to include menu.inc file in this file. It simply includes menu.inc but no stylesheets and no javascripts. Can anyone tell me why is this happening and what can i do to solve this problem

I cant even visit the links from SOIT/soit.php page where as i can go to those same pages from index.php. Please if anyone knows the answer help me out

Ensure that your paths are correct. Remember that you will have to use "../" at the start of the path string to include these other files. Includes can use relative or absolute (from webroot) paths (not public root) and javascript /CSS can use relative or absolute (public root) but not webroot. I suggest that you change everything to absolute if you're including js/CSS files, otherwise the your pages will look for files that are not there.

BTW:
I take it you haven't attempted to include js/CSS with the include function. Scripts and link tags are required for these.

The problem with your links not functioning is probably because they are set in relative format. Change all your links to absolute (with regard to public root).

So if you had this in SOIT folder file:

<a href="mypage.php" ...

It should be

<a href="/SOIT/mypage.php ...

One trick I use (workaround) for when I'm using a local server and remote together is this:
I place these defnitions in my com.inc.php file and make sure it's included in every main page.

if on local: $root_folder = "/mysite/"; if remote: $root_folder = "/";

define("HTML_ROOT", $root_folder); //the bit after localhost 
define("ROOT",$_SERVER['DOCUMENT_ROOT'] . $root_folder);

Then everything is accessed via these constants:

<?php
  include(ROOT . "includes/myincludefile.inc.php");
?>
<link href= "<?=HTML_ROOT;?>cssfiles/screen.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen" />
<script src= "<?=HTML_ROOT;?>scripts/myscript.js" type="text/javascript"></script>

Using .inc files is a bad idea in terms of security. If a user tries to view that file directly and the server doesn't interpret it through PHP, the user will be able to see your code!

Try include_path="C:\PHP_includes";

instead of what you have in your php.ini. Remember after you change your php.ini, you have to restart the web service.

Using .inc files is a bad idea in terms of security. If a user tries to view that file directly and the server doesn't interpret it through PHP, the user will be able to see your code!

This is very important, hence the naming: mypage.inc.php or just mypage.php.

This article has been dead for over six months. Start a new discussion instead.