Perl Getting An Error With Refferrer
my $refer = $ENV{HTTP_REFERER}; my $gk1 = substr($str1, -4); if ($gk1 = .swf) { my $antigk = 'gk detected'; } else { my $antigk = $link; } what is wrong with this code? i get
Solution 1:
You probably have this near the top of your index_dl.pm
file:
use strict;
This means that you need to declare each variable with my
before you use it:
my $str1;
You probably want to declare $antigk
before your if-else block and maybe you really want:
my $antigk = $link;
if ($gk1 eq '.swf') { $antigk = "gk detected"; }
else
{ $antigk = $link; }
Solution 2:
# In this line you store the HTTP referer in the variable $refer
my $refer = $ENV{HTTP_REFERER};
# Then, in this link you take a substring of the variable $str1.
# But you don't have a variable called $str1.
# Perhaps you actually wanted to take a substring of $refer?
my $gk1 = substr($str1, -4);
# This next line will be a syntax error because you need to quote
# strings (and .swf is a string. This should be '.swf'.
# Also, you are using '='. This is the assignment operator. This
# will set $pgk1 to the value '.swf'. That's not what you want to do.
# You want to compare $pgk1 and '.swf'. For that you need the comparison
# operator - which is 'eq'.
# So this whole line should be:
# if ($gk1 eq '.swf') {
if ($gk1 = .swf) {
# It's good that you are declaring $antigk using 'my'. But 'my' only
# works within a code block. So you're setting $antigk here, but the
# value will be lost as soon as you pass the end of the code block
# (which is the '}' on the very next line).
# Better to declare $antigk (with 'my $antigk') before the 'if' statement.
my $antigk = "gk detected";
} else {
my $antigk = $link;
}
In general, you are making some very basic programming errors here. I assume that you think you learn best by jumping into a problem and Googling for help. I don't think that approach is working for you. I'd strongly recommend talking a couple of days to work through a beginner Perl book (like "Learning Perl") before continuing with this project.
Solution 3:
Apart of toolic's answer, I guess you have to change those lines:
my $refer = $ENV{HTTP_REFERER};
my $gk1 = substr($str1, -4);
to these ones:
my $refer = $ENV{HTTP_REFERER};
my $gk1 = substr($refer, -4);
# ^^^^^^
Post a Comment for "Perl Getting An Error With Refferrer"