Jump to content

Re: PHP Include Files not working


marotta1

Recommended Posts

Hi all,

 

I'm using the following in my .htaccess file to have extensionless page URL's. The web pages are PHP pages like example-video.php.

 

<Files ~ ^(example-videos|example-videos2)$>
ForceType x-mapp-php
</Files>

 

The problem I'm having is my PHP include files are not working. They are not displaying what they should output on the pages. They are simple include files with just an echo function to output some html. What would cause this to happen?

 

Any help would be very much appreciated.

 

Link to comment
Share on other sites

Here is an example of the include files.

 

<?php echo "
    <ul>
<li><a href=\"index.html\" class=\"menu\">Home</a></li>
<li><a href=\"about.html\" class=\"menu\">About Us</a></li>
<!-- li><a href=\"merchandise.html\" class=\"menu\">Merchandise</a></li -->
<li><a href=\"gallery.html\" class=\"menu\">Gallery</a></li>
<li><a href=\"wedding_packages.html\" class=\"menu\">Packages</a></li>
<li><a href=\"events.html\" class=\"menu\">Events</a></li>
<li><a href=\"legacy_team.html\" class=\"menu\">Legacy Team</a></li>
<li><a href=\"links.html\" class=\"menu\">Links</a></li>
<li><a href=\"contact.html\" class=\"menu\">Contact Us</a></li>
<li><a href=\"example-videos\" class=\"menu\">More...</a></li>	
</ul>";
?>

 

<?php echo "<a href=\"javascript:window.location = 'http://www.socialmarker.com/?link='+encodeURIComponent (location.href)+'&title='+encodeURIComponent( document.title);\"><img class=\"displayed\" src= \"http://www.socialmarker.com/bookmark.gif\" border=\"0\" alt=\"Bookmark this Page\" /></a><noscript><a href=\"http://www.socialmarker.com\" >Social Bookmarking</a></noscript>";
?>

 

The include files are in a folder right under the root (domain name) and are very simple. Not sure why, but it seems to me the problem has to lie somewhere else.

Link to comment
Share on other sites

Sorry, thought you wanted to see the contents of the include files. This is where I am calling the first include. It's just used to output html in the domain for http://www.mydomainname.com/example-videos.php page.

 

<div class="printhide">
   <div class="menubackground">
     <?php include('includes/menu.php'); ?>
   </div> <!-- /menubackground -->
  </div> <!-- /printhide -->

Link to comment
Share on other sites

(I thought I replied to this, but I guess not.)

 

Your code works for me (when I tried it a couple of days ago) except I had a problem browsing to the main file. I am guessing x-mapp-php is CGI specific and I had to use a server module value to get the main file to work.

 

Your include() is using a file system path. Functionally, that has nothing to do with what your .htaccess file is doing as that only affects files that are requested from the web server using the http/https protocols.

 

Either the path in the include() statement is not correct or the file name is not correct.

 

'includes/menu.php' looks for a folder called includes, starting in the folder where the script containing the include() statement is located and/or somewhere on the include_path setting.

 

I recommend forming an absolute file system path using $_SERVER['DOCUMENT_ROOT'] so that include() statements can find the path/file no matter what the path is or where the file is that is including another file.

 

If your includes folder is located in the document root, then -

 

<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/menu.php'); ?>

Link to comment
Share on other sites

it's still not working.

Well what exactly is it doing or not doing? What file name are you browsing to? What is your current code? Tell us what you see in front of you and what is in your browser when you do a "view source".

 

We only see the information you provide in your posts and based on what little specific information you have provided so far (and that the code worked for me), my guess is that php is not being parsed on your server.

 

The .htaccess information you posted (assuming that x-mapp-php has meaning on a GCI/php system - it caused a file download prompt on a server module/php system) causes the extension-less files example-videos. or example-videos2. to be treated as php files on the server. It does nothing to files named example-videos.php or example-videos2.php.

Link to comment
Share on other sites

Sorry for being so vague last time. It's been tough to get to this due to business. I am using an include which is what shows up in the view source.

 

<?php include('includes/menu.php'); ?>

 

I've tried the server root way as well.

 

<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/menu.php'); ?>

 

I've also tried it with the server path:

 

<?php include('/kunden/homepages/47/d24232649/htdocs/Wedding
Video/includes/menu.php'); ?>

 

The webpage is www.domainname.com/example-videos . It is saved without the .php extension and included in the Forcetype statement in .htaccess. I did find out PHP is run as CGI on this server and the Apache version is 1.3.34.

 

The same include file works fine on the other pages with .php extensions or with .html extensions using AddType x-mapp-php4.

Link to comment
Share on other sites

If its showing up in the source then the server is not parsing it or there is an echo with ' ' brackets which takes what ever is in those brackets and prints it whether there is php code in it or not. If thats the case then change them to "". If theres nothing like that then your server is not running php. Is that in a html file? if so then you need to put in the htaccess for the server to use php in html files. Example: AddType application/x-httpd-php .html

Link to comment
Share on other sites

The echo already has  " " double quotes. It is not in an html file. Some of the other pages of the site are .html pages. The include file is inside of a webpage saved without an extension. It was previously saved with a .php extension but no longer is. That is why I'm using Forcetype; to get the URL to work without .php at the end.

 

If there was a way to use:

 

AddType application/x-mapp-php NoExtensionHere

 

it'd probably work great, lol.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.