My mom's site gets lots of visitors but few buyers. So my idea is that I put a small black bar at the very top of the page that tells users that if they order in the next 30 minutes they get 10% off. I figure that I'd implement it like this:
1. Put <!--#include virtual="countdown.cgi"--> at the top of each .html page.
2. <countdown.cgi> tries to read a cookie.
---- 2a. If the cookie exists I read the time it was set, figure out how much time remains, and output the number of minutes remaining to my black bar.
---- 2b. If the cookie doesn't exist then <countdown.cgi> calls <setcookie.cgi>, which sets the cookie and then returns the user to the original <.html> page.
Where I'm stuck is (2b): My [print:"Location..."] doesn't work when it's in a CGI file that's called via SSI, it works only if the CGI file is called directly.
I can think of two possible solutions, neither of them attractive:
A: Have JavaScript try to read and set the cookie. Downside is that it won't work if JavaScript is off, and I like to avoid JavaScript when I can.
B: Make each file on the website a <.cgi> file instead of a <.html> file, and have it run the code and then build the page. But this adds another level of complexity that I'd really, really prefer to avoid.
Any ideas? Thanks for your help!
Also, check your error logs. Your script could be throwing an error when called by SSI that it doesn't throw when called directly.
I run a site that does something similar and my solution was to code the pages in PHP (very little coding difference from HTML pages actually... PHP is merely embedded in the file). In the first line of each file I begin the PHP code, read and set cookies, etc. This is possible because you can set cookie (and other) headers using PHP if you do it before any other headers (ie the Content-type: header) are set. To do this, you embed the Cookie setting PHP code before anything at all is output to the browser. Here's an example:
<?php
if ($CookieName){
$cookieData = explode("&", $CookieName);
$this = current($cookieData);
while ($this){
$temp = explode("=", $this);
$cookieHash['$temp[0]'] = $temp[1];
$this = next($cookieData);
}
$AccessTime = $cookieHash['time'];
} else {
$AccessTime = mktime();
}
setcookie("CookieName", "time=".$AccessTime, time() + (365 * 86400), '/', 'yourdomain.com');
# in the next line, 108000 is the number of seconds in 30 minutes...
$CountDownSeconds = $AccessTime - mktime() + 108000;
$CountDownMinutes = round(($CountDownSeconds/60),0);
?>
<html>
<head>
</head>
<body><?php
if ($CountDownMinutes > 0){
?>
<center>
<h2>Welcome to Our Countdown Sale!</h2>
<p>Purchase within <b><?php echo $CountDownMinutes;?> minutes</b> and we'll give you 6% off our already ridiculously low prices!</p>
<?php
}
?></body>
</html>
Something like that...