Forum Moderators: phranque

Message Too Old, No Replies

Problem with conditional ssi

Problem may have started after move to different server

         

kelly5518

10:28 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



Hi,

I'm using the following conditional ssi call to include a certain file depending on the day of the month (only showing day 1 and day 7 ... which is today's date:


<!--#config timefmt="%d" -->
<!--#if expr="$DATE_LOCAL = 01" -->
<!--#include file="tip1.html" -->
<!--#elif expr="$DATE_LOCAL = 07" -->
<!--#include file="tip7.html" -->
<!--#endif -->

So, today it should be including the file called tip7.html into a page called tod.shtml, but it's not working. No error messages or anything, just not including the file. All files are in the same directory.

Any suggestions appreciated!

Thanks!

jdMorgan

12:02 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Modifying some code I have on a live server, I came up with:

<!--#config timefmt="%d" -->
<!--#if expr="${DATE_LOCAL} = /01/" -->
<!--#include virtual="tip1.html" -->
<!--#elif expr="${DATE_LOCAL} = /07/" -->
<!--#include virtual="tip7.html" -->
<!--#else -->
<!--#set var="errmsg" value=" No date handler file available " -->
<!--#echo var="errmsg" -->
<!--#endif -->

Jim

kelly5518

10:59 am on Feb 8, 2007 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for trying to help. However, I'm getting some strange results. Sometimes it displays the right file and sometimes it displays the content of files for other dates, even though today's date is the 8th. It seems like your code should be displaying the error message since today's date is not one of the options.

Aside from that, I've changed my statements to look like yours, but if I keep hitting refresh repeatedly, sometimes I get different files included. It's strange.

Any ideas?

Here's my complete code:


<!--#config timefmt="%d" -->
<!--#if expr="${DATE_LOCAL} = /01/" -->
<!--#include virtual="tip1.html" -->
<!--#elif expr="${DATE_LOCAL} = /02/" -->
<!--#include virtual="tip2.html" -->
<!--#elif expr="${DATE_LOCAL} = /03/" -->
<!--#include virtual="tip3.html" -->
<!--#elif expr="${DATE_LOCAL} = /04/" -->
<!--#include virtual="tip4.html" -->
<!--#elif expr="${DATE_LOCAL} = /05/" -->
<!--#include virtual="tip5.html" -->
<!--#elif expr="${DATE_LOCAL} = /06/" -->
<!--#include virtual="tip6.html" -->
<!--#elif expr="${DATE_LOCAL} = /07/" -->
<!--#include virtual="tip7.html" -->
<!--#elif expr="${DATE_LOCAL} = /08/" -->
<!--#include virtual="tip8.html" -->
<!--#elif expr="${DATE_LOCAL} = /09/" -->
<!--#include virtual="tip9.html" -->
<!--#elif expr="${DATE_LOCAL} = /10/" -->
<!--#include virtual="tip10.html" -->
<!--#elif expr="${DATE_LOCAL} = /11/" -->
<!--#include virtual="tip11.html" -->
<!--#elif expr="${DATE_LOCAL} = /12/" -->
<!--#include virtual="tip12.html" -->
<!--#elif expr="${DATE_LOCAL} = /13/" -->
<!--#include virtual="tip13.html" -->
<!--#elif expr="${DATE_LOCAL} = /14/" -->
<!--#include virtual="tip14.html" -->
<!--#elif expr="${DATE_LOCAL} = /15/" -->
<!--#include virtual="tip15.html" -->
<!--#elif expr="${DATE_LOCAL} = /16/" -->
<!--#include virtual="tip16.html" -->
<!--#elif expr="${DATE_LOCAL} = /17/" -->
<!--#include virtual="tip17.html" -->
<!--#elif expr="${DATE_LOCAL} = /18/" -->
<!--#include virtual="tip18.html" -->
<!--#elif expr="${DATE_LOCAL} = /19/" -->
<!--#include virtual="tip19.html" -->
<!--#elif expr="${DATE_LOCAL} = /20/" -->
<!--#include virtual="tip20.html" -->
<!--#elif expr="${DATE_LOCAL} = /21/" -->
<!--#include virtual="tip21.html" -->
<!--#elif expr="${DATE_LOCAL} = /22/" -->
<!--#include virtual="tip22.html" -->
<!--#elif expr="${DATE_LOCAL} = /23/" -->
<!--#include virtual="tip23.html" -->
<!--#elif expr="${DATE_LOCAL} = /24/" -->
<!--#include virtual="tip24.html" -->
<!--#elif expr="${DATE_LOCAL} = /25/" -->
<!--#include virtual="tip25.html" -->
<!--#elif expr="${DATE_LOCAL} = /26/" -->
<!--#include virtual="tip26.html" -->
<!--#elif expr="${DATE_LOCAL} = /27/" -->
<!--#include virtual="tip27.html" -->
<!--#elif expr="${DATE_LOCAL} = /28/" -->
<!--#include virtual="tip28.html" -->
<!--#elif expr="${DATE_LOCAL} = /29/" -->
<!--#include virtual="tip29.html" -->
<!--#elif expr="${DATE_LOCAL} = /30/" -->
<!--#include virtual="tip30.html" -->
<!--#elif expr="${DATE_LOCAL} = /31/" -->
<!--#include virtual="tip31.html" -->

<!--#else -->
<!--#set var="errmsg" value=" No date handler file available " -->
<!--#echo var="errmsg" -->
<!--#endif -->

Thanks for taking a look.

kelly

jdMorgan

10:44 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, the next step would be to check and see if the date is being properly returned, using an echo directive. Something like:

<!--#config timefmt="%d" -->
<!--#echo var="${DATE_LOCAL}" -->
<!--#if expr="${DATE_LOCAL} = /01/" -->

at the top of the code.

Jim

kelly5518

8:56 pm on Feb 9, 2007 (gmt 0)

10+ Year Member



Hi,

Sorry for the delay in replying. This is what it's returning: (none)

However, it must be returning something, because it does display the contents of a file, just not the right one.
:-\

jdMorgan

11:42 pm on Feb 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For simplicity, I didn't test with 'include_virtual' since I don't have the time-variable files that you do, but the following works unfailingly on my server:

<!--#config timefmt="%S" -->
<p>DATE_LOCAL &quot;%S&quot; = <!--#echo var="DATE_LOCAL" -->
<!--#if expr="$DATE_LOCAL = /0[0-9]/" -->
<br>Second = 0-9
<!--#elif expr="$DATE_LOCAL = /1[0-9]/" -->
<br>Second = 10-19
<!--#elif expr="$DATE_LOCAL = /2[0-9]/" -->
<br>Second = 20-29
<!--#elif expr="$DATE_LOCAL = /3[0-9]/" -->
<br>Second = 30-39
<!--#elif expr="$DATE_LOCAL = /4[0-9]/" -->
<br>Second = 40-49
<!--#else -->
<br>Second = 50-59
<!--#endif -->
</p>

The code just indicates which ten-second part of a minute it is when the page is loaded. Note that this page is marked as non-cacheable so that it must be loaded every time I request it in the browser; Otherwise, I'd just see whatever page my browser had previously cached.

Note also that the DATE_LOCAL variable references are different between the "#echo var=" and "expr=" directives.

Jim

kelly5518

2:23 pm on Feb 10, 2007 (gmt 0)

10+ Year Member



Hi,

Assuming I'm understanding your last post, it looks like mine is returning the seconds incorrectly. It looks like it's reading the "hours" rather than the seconds because this is what your code returned on my page:

DATE_LOCAL "%S" = Saturday, 10-Feb-2007 09:20:33 EST
Second = 0-9

Is that what you make out of it?

Thanks!

Edit: I added the no-cache tag to my page as well, but same results.

jdMorgan

4:25 pm on Feb 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From what you posted, it's clear that the "config timefmt" directive is not working on your server.

The output you should have seen from the first 'echo' directive is:

DATE_LOCAL "%S" = 33

So, it's apparent that your server did not accept the time format configuration, and used the default configuration instead, resulting in the entire date and time being printed.

The subsequent code then matched on the the first "if" statement because it found two matching digits -- the "00" in "2007". So it printed "Second = 0-9."

This might be an SSI misconfiguration or a permissions restriction, and all I can suggest is to contact your host or server admin and ask them why "config timefmt" won't work.

Jim

kelly5518

12:15 pm on Feb 12, 2007 (gmt 0)

10+ Year Member



Hi Jim. You're right. I had jumped to the conclusion that it was displaying the hours instead of seconds, but that's not the case at all.

I'll contact my server admin.

Thanks so much for all of your help!

kelly