Hi:
I am working on a plug-in to limit the number of times different users can use my search function (Seems a couple big companies seem to think they can run 1000's of queries a day on my DB and not have to pay for it!)
Anyway, my thought it to track searches by IP and Username... those with no username (Guests) will get 10 searches, users 50, and anyone who "donates" will get unlimited.
So I am looking at inserting some code into search.pm, like this: (NOTE: My only changes to existing code are inside the "######## Dave Mod" comments)
sub search {
# ------------------------------------------------------------------
# Do the search and print out the results.
#
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'search_results', \&query, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('search', $results);
}
else {
######## Dave Mod
my ($rec) = @_;
my $username = $rec->{'Username'};
my $ip = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR} || 'None';
my $member = "No"; #$IN->param('member');
my $number;
my $count;
my $s_db = $Links::DB->table('Search_Count');
# Set date variable to today's date.
Links::init_date();
my $today = GT::Date::date_get();
my $date = $today;
# Update the search count unless this is the first search.
$s_db->add ( { IP => $ip, Date => $date, User => $username, Count => $member } );
if ($count >= $number) {
print $IN->header();
print Links::SiteHTML::display ('search_limit', $results);
}
else {
######## End Dave Mod
print $IN->header();
print Links::SiteHTML::display ('search_results', $results);
}
Note this is very simplified right now-- I am still trying to get the basics to work before I throw in all the checks! So $member is hard-coded to no, the date works, IP works, etc. I will eventually add in an update to update the count for existing records... but right now I am just trying to get the dang Username to appear!!!! (If I hard-code $username ="Guest"; or something, the above will add to database Search_Count, but trying to get the darn Username is not working)
Can anyone give me a pointer so I can get this variable to appear!
BTW, I did do a variable dump on the Search Resuts page, and both "Username" and "member" do show up, so I KNOW they there to grab- I just cannot seem to grab them!!!!
TIA!
dave
Big Cartoon DataBase
Big Comic Book DataBase
I am working on a plug-in to limit the number of times different users can use my search function (Seems a couple big companies seem to think they can run 1000's of queries a day on my DB and not have to pay for it!)
Anyway, my thought it to track searches by IP and Username... those with no username (Guests) will get 10 searches, users 50, and anyone who "donates" will get unlimited.
So I am looking at inserting some code into search.pm, like this: (NOTE: My only changes to existing code are inside the "######## Dave Mod" comments)
Code:
sub search {
# ------------------------------------------------------------------
# Do the search and print out the results.
#
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'search_results', \&query, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('search', $results);
}
else {
######## Dave Mod
my ($rec) = @_;
my $username = $rec->{'Username'};
my $ip = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR} || 'None';
my $member = "No"; #$IN->param('member');
my $number;
my $count;
my $s_db = $Links::DB->table('Search_Count');
# Set date variable to today's date.
Links::init_date();
my $today = GT::Date::date_get();
my $date = $today;
# Update the search count unless this is the first search.
$s_db->add ( { IP => $ip, Date => $date, User => $username, Count => $member } );
if ($count >= $number) {
print $IN->header();
print Links::SiteHTML::display ('search_limit', $results);
}
else {
######## End Dave Mod
print $IN->header();
print Links::SiteHTML::display ('search_results', $results);
}
Note this is very simplified right now-- I am still trying to get the basics to work before I throw in all the checks! So $member is hard-coded to no, the date works, IP works, etc. I will eventually add in an update to update the count for existing records... but right now I am just trying to get the dang Username to appear!!!! (If I hard-code $username ="Guest"; or something, the above will add to database Search_Count, but trying to get the darn Username is not working)
Can anyone give me a pointer so I can get this variable to appear!
BTW, I did do a variable dump on the Search Resuts page, and both "Username" and "member" do show up, so I KNOW they there to grab- I just cannot seem to grab them!!!!
TIA!
dave
Big Cartoon DataBase
Big Comic Book DataBase