$referer = "-";
if (exists($ENV{'HTTP_REFERER'})) {
$string = $ENV{'HTTP_REFERER'};
&sanitize;
$referer = $string;
}$usragnt = "-";
if (exists($ENV{'HTTP_USER_AGENT'})) {
$string = $ENV{'HTTP_USER_AGENT'};
&sanitize;
$usragnt = $string;
}
&sanivar ("\'HTTP_REFERER\'", $referer, "-");
&sanivar ("\'HTTP_USER_AGENT\'", $usragnt, "-");# If the server environment variable exists, sanitize it and copy it to the named program variable.
sub sanivar {
local($string);
my($senvar, $locvar, $defval) = @_;
$string = $defval;
if (exists($ENV{$senvar})) {
$string = $ENV{$senvar};
&sanitize;
}
$$locvar = $string;
}
Also, the local variable pointed to by symbolic reference '$$locvar' is not updated.
Any suggestion or corrections to this code, or suggestions on a better implementation would be most welcome.
Thanks!
Jim
I ended up just using:
$referer = &sanivar($ENV{'HTTP_REFERER'} ¦¦ "-");
If I get some more time, I'll go back and try your approach, though -- I hate leaving 'mysteries' unsolved just because I run out of time on a project...
Thanks,
Jim
Note to readers: Replace the broken pipe "¦" characters with solid pipe characters; Posting on this forum modifies the pipe characters.
btw: you don't need the & in front of subroutine-calls, iirc, there was even something possibly bad with using them, but I don't quite remember what it was.
also, when using ¦¦, you're checking for three things: an empty string, a zero-value or an undefined value. that might, in this case, be just fine for you, but it's not always what you'd want, so watch out.