SSI and .php file

Posted on 2005-04-21
Last Modified: 2008-03-17

In my website there is an .htaccess file which contains the following lines :

php_flag register_globals off
AddHandler server-parsed .htm
AddHandler server-parsed .html

In order to enable SSI banner, I added an aditional line : AddHandler server-parsed .php

After that, the main page index.php file doesn't open. It asked to download a file which contain the following codes :

$catname = "";
$catid = "";
$val_string = "";

if (isset($_REQUEST["catid"])) {
      $catid = round($_REQUEST["catid"]);
if (isset($_REQUEST["setlang"])) {
      $_SESSION["la"] = $_REQUEST["setlang"];

if ($catid) {
      $sql = "select catname from $cat_tbl where catid = $catid";
      $row = mysql_fetch_array(q($sql));
      $catname = " :: " . $row["catname"];
      $fp = 1;      

if (!$special_mode) {
      if (isset($menu_ordinary)) { print $menu_ordinary; }

if (!empty($catid)) {
      // Write out the link bar
// Security check
if (file_exists("install.php"))
      print "<p><center><b><font color='red'>SECURITY WARNING</font></b><br />You have not followed our instructions to       delete install.php
      immediately after install. Leaving this file here is a <u>major</u> security problem and opens your site up
      to wild hacking.</center></p>";      
print '<table border="0" width="100%" cellspacing="0" cellpadding="10" valign="top"><tr><td width="100%">';           

// If we are on the frontpage, write out welcome message along with flags
if ($catid==0 AND !$special_mode)
      echo "<h2>$name_of_site</h2>";
      echo formatString($welcome_message, array("$name_of_site"));
      include "templates/flags_frontpage.html";
<table border="0" width="100%" bgcolor="#A9B8D1" cellspacing="0" cellpadding="0">
    <td width="100%" height="1"><img border="0" src="layout_images/spacerbig.gif" width="1" height="1" alt='' /></td>


// If we have featured ads
if (!empty($set_special) AND !isset($_REQUEST["catid"]))
      print "<table border='0' width='100%'><tr><td valign='top' width='80%'>";
// Print out categories

// This is the column containing special ads
if (!empty($set_special) AND !isset($_REQUEST["catid"])) {
      print "</td><td valign='top' width='20%'>";
      include "special.php";
      print "</td></tr></table>";

// Print out ad-listings

// Counter (if activated from admin area)

if (isset($set_count_dynamic))
      $str = "";
      if (isset($validation))
            if ($validation<>"")
                  $str = " where valid=1";
      $row = mysql_fetch_array(mysql_query("select count(ad_username) from $ads_tbl $str"));
      $upd_ads = $row["count(ad_username)"];
      $row = mysql_fetch_array(mysql_query("select count(email) from $usr_tbl"));
      $upd_users = $row["count(email)"];
      $row = mysql_fetch_array(mysql_query("select sum(sitehits) from $ads_tbl $str"));
      $upd_sitehits = $row["sum(sitehits)"];

      if (!$upd_sitehits)
            $upd_sitehits = 0;
      $la_s_bar = formatString($la_s_bar, array("$upd_users","$upd_ads","$upd_sitehits"));
      $show_bar = 1;

print "</td></tr></table>\n";
print "<!-- ## INDEX.PHP END ## -->";


Now my question is where I am making mistake ?

Question by:Sohel Rana
    LVL 7

    Expert Comment

    Hi there rsdn,

    I'm not sure what level you're at with this stuff, however here are my comments. What you've got there is a PHP file. PHP is a scripting language, rather like SSI. Your new Apache directive has told Apache that it should handle your PHP files using Apache's SSI handler. This means that Apache will process all the SSI commands from your PHP file that it recognises, but the PHP commands will now not be processed.

    From your comment, it sounds like you want to insert some additional stuff at the top of that index.php page. If that's what you want to do, I'd suggest editing the index.php file and adding some print("<h1>my heading</h1>"); lines, something like that. Use the PHP language to add the stuff you want.

    I believe it may be possible to use multiple handlers on a page using Apache, but it's probably not going to be necessary for what you're trying to do.

    Hope that helps
    LVL 16

    Author Comment

    by:Sohel Rana
    Hi JP:

    Thanks for your comment. I am not good in php, so sorry for asking you additional question. Rightnow, I place the code inside header.html file :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "">
    <title>%SITENAME% %PAGE%</title>
    <link rel="stylesheet" href="style.css" type="text/css" />

    <!--#include virtual="/SSI/asianclassified.htm" -->

    <script language="JavaScript">
    function openPage(URL) {,"Large","toolbar=no,width=500,height=500,status=no,scrollbars=yes,resize=no,menubars=no");

    <body bgcolor="#FFFFFF">


    Can you tell me where I need to change in header.html ? Or I need to place this code inside index.php file? I place this code to header.html because I need to show the banner in all pages, rather than main or index.php page.

    LVL 7

    Accepted Solution

    1. copy header.html to header.php
    2. in header.php, change %SITENAME% to <?php print($SITENAME) ?>
    3. in header.php change %PAGE% to <?php print($PAGE) ?>
    4. in file index.php, add require("header.php"); at the start, just after the first <?php

    LVL 25

    Assisted Solution

    The equivalent to this: <!--#include virtual="/SSI/asianclassified.htm" --> in PHP is:


    This is the usual technique for combining PHP and SSI - doing both in the same file is pretty hopeless (I don't think you can have multiple handlers for the same file type), but you can at least call one from the other using virtual() and #include virtual. You need to use virtual and not include or require as it spawns a new apache sub-request, and that sub request can use a different handler.

    Your HTML is pretty invalid which won't help - you've got content outside your body tag.

    LVL 16

    Author Comment

    by:Sohel Rana
    Thanks everyone for your input.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now