3 lines (of correct syntax) is all that's required:
1. how to include text output of a perl script in webpage
(it's
<!-- #include virtual="myscript.pl" -->
or something.. iirc)
2. the name of the environment variable that gives the time on the
local server
($ENV{Local_Time} or something?)
3. the name of an environment variable from which I could deduce as
accurately as possible, the country from which the web page request
originated
($ENV{HTTP_REFERER}) ??
(I'm writing a short script to only display a contact telephone number
between 9am & 5pm when the page was requested from within the UK,
otherwise display a contact form - but can't quite remember the correct
syntax) |
Clarification of Question by
gan-ga
on
03 Jan 2003 13:34 PST
pseudocode so far, any help to get this done quickly appreciated.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
domainextension = regex on $ENV{'original request from'}
timenow = regex on $ENV{'servers local time'} & convert to numeric variable
if(domainextension=='co.uk'&& timenow >= 900 && timenow <= 1700){
print "Please contact me on xxxxx xxx xxx";
}
else
{
print "<form action ='./cgi-bin/contactform.pl'>\n";
print "Enter email <input type='text' size='30'><br>\n";
print "Enter comment <input type='text' size='30'\n";
print "</form>\n";
}
|
Request for Question Clarification by
jes5199-ga
on
03 Jan 2003 13:39 PST
what web server are you using?
some of these things are done differently with different servers
so, are you using Apache or Microsoft or something else?
~jes5199-ga
|
Clarification of Question by
gan-ga
on
03 Jan 2003 13:50 PST
Hello jes5199,
Unix / Apache as far as I'm aware. I'll check and post back as soon as
I can, give me a few minutes..
Here's what I have so far, can you help me out with getting hold of
the current time on my server & deciding if it's between 9am and 5pm
(the localtime environment variable & maybe a couple of regexes on
it)?
Cheers
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$domainextension = $ENV{'REMOTE_HOST'};
$domainextension =~ tr/A-Z/a-z/;
$domainextension =~ s/.*\.//;
$timenow = regex on $ENV{'servers local time'} & convert 24 hr clock
to 4 digit numeric variable
if($domainextension=='uk'&& $timenow >= 900 && $timenow <= 1700){
print "Please contact me on xxxxx xxx xxx";
}
else
{
print "<form action ='./cgi-bin/contactform.pl'>\n";
print "Enter email <input type='text' size='30'><br>\n";
print "Enter comment <input type='text' size='30'\n";
print "</form>\n";
}
|
Clarification of Question by
gan-ga
on
03 Jan 2003 13:53 PST
Yes, Unix & Apache/1.3.22 Server
|
Clarification of Question by
gan-ga
on
03 Jan 2003 14:15 PST
Just tested the code, works on my server so far. I can see I might run
into trouble deciding on a user's whereabouts on the basis of
REMOTE_HOST, but that's not too important. Avoiding displaying a
contact phone number at night, based on the server's time, is the
really important thing.
I'm stumped now.. over to you?
|
ok -- to retrieve the time as variables:
$time = localtime();
$time =~ /(..)\:(..)\:(..)/;
$hours = $1;
$minutes = $2;
$seconds = $3;
if you need help checking to see if these variables are in your range,
just ask for further clarification and i'll hack it together
----
from your initial question (although i think you've already got it)
<!--#include virtual="/wherever/whatever.pl" -->
is the correct syntax according to
http://httpd.apache.org/docs/mod/mod_include.html
REMOTE_HOST is the correct variable to find out what domain a person's
computer is in, but this can be inaccurate or just left out (ie, not
all .coms are in the USA, and not all .tv are in Tuvalu, and many IP
addresses aren't registered at all)
i'd try using REMOTE_ADDR and feeding the IP addresses through
http://where-is.info/freebies.html
of course, then you'd need a whole new perl script to submit and parse
that data |
Clarification of Answer by
jes5199-ga
on
03 Jan 2003 14:20 PST
oops, got another clarification request while i was typing. in a
second i'll have the code to check the time vars
|
Clarification of Answer by
jes5199-ga
on
03 Jan 2003 14:28 PST
$opentime = "0900";
$closetime = "1700";
$time = localtime();
$time =~ /(..)\:(..)\:(..)/;
$hours = $1;
$minutes = $2;
$seconds = $3;
if( ($hours.$minutes ge $opentime) && ($hours.$minutes le $closetime) )
{
print "OPEN\n"
}
|
Clarification of Answer by
jes5199-ga
on
03 Jan 2003 14:35 PST
google answers likes me to list what i typed into the search engine to
get my results...
"apache CGI environment variables"
"perl regexp"
i think that was all.
|
Clarification of Answer by
jes5199-ga
on
03 Jan 2003 14:37 PST
one caveat about the code
i used string compares instead of numeric: that means
0900 works
but 900 does not
because 900 looks a lot like 9000 to the perl interpreter, it will
always be later than the time generated by the localtime call
|