0

I am currently working on developing a personal website. It's not my first time doing this, but this is my first major foray into implementing SSI. I've run myself into a wall, however, with an if-else directive that uses one of the CGI environment variables as part of its comparison.

Even after some limited attempts at debugging, all of the output and documentation that I have means that the comparisons being made should fail outright. This is not the case, and the wrong evaluation is being made by the if-else directive.

Here's the code in the file index.shtml:

<head>
    <!--#set var="page" value="Home" -->
    <!--#include file="headlinks.shtml" -->
    <style>
        img#ref { float: right; margin-left: 8px; border-width: 0px;  }
    </style>
</head>

Here's the code in the file headlinks.shtml:

<title><!--#echo var="page" --> &ndash; <!--#echo var="HTTP_HOST" --></title>
<!--#set var="docroot" value="${DOCUMENT_ROOT}" -->
<!--#echo var="docroot" -->
<!--#if expr="( $docroot != '/Applications/MAMP/htdocs' ) || ( $docroot != '/home/dragarch/public_html' )" -->
    <link rel="stylesheet" type="text/css" href="../style.css">
    <link rel="shortcut icon" type="image/svg+xml" href="../favicon.svg" />
<!--#else -->
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="shortcut icon" type="image/svg+xml" href="favicon.svg" />
<!--#endif -->

And here's the output for the file index.shtml:

    <title>Home &ndash; dragarch</title>

/Applications/MAMP/htdocs

    <link rel="stylesheet" type="text/css" href="../style.css">
    <link rel="shortcut icon" type="image/svg+xml" href="../favicon.svg" />

Both style.css and favicon.svg are in the document root with index.shtml, so the if directive should fail and default to the output of the else directive. As you can see, while the document root (which is currently the MAMP htdocs folder on my own notebook) is correct according to the output of the echo directive, the comparison in the if-else directive fails to compare the strings properly.

I'm using this page for my documentation: http://httpd.apache.org/docs/2.2/mod/mod_include.html

I'm at a complete loss as to why this is the case, and need a bit of help here.

EDIT: I should note that dragarch is a hostname that I configured in /etc/hosts to point to 127.0.0.1 so I could test the site without having to use localhost. It has no real effect on the functionality of anything, other than to just act as a prettier hostname to use.

hakre
  • 193,403
  • 52
  • 435
  • 836
Calyo Delphi
  • 329
  • 1
  • 3
  • 16

1 Answers1

0

Simple check: try splitting the if statement up into two conditionals before your else. See which one is being incorrectly evaluated as true. If both conditions are, then you need to double check how the conditionals are being evaluated. Perhaps they are both returning true due to the expr = statement? I dont know a darn thing about ssi but i do know that in some languages, saying var_name = is always true, and == is a comparison.

  • The expr= is part of the syntax for the if directive. Everything inside the quotes after expr= is the conditional that is being tested. – Calyo Delphi Nov 09 '12 at 06:19
  • Thanks for the input and the resulting epiphany. :) Just gotta turn this into an xor expression. – Calyo Delphi Nov 09 '12 at 06:32
  • You're welcome! I actively tutor students in a general engineering c programming course every week so it came naturally to jump at the opportunity to help, even if all i did was get you to re think your code a bit <. –  Nov 09 '12 at 06:47