hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Software and Control Panels : script help
Reply

Forum Jump

script help

Reply Post New Thread In Hosting Software and Control Panels Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
WHT Addict
 
Join Date: Sep 2000
Posts: 172
I have a counter program and what to add to it slightly by having it check to see if the hit is from several IP's which my wife uses so the count stays the same if it is.

What I know about perl programing will fit on a matchbook so I need lots of help.

I'm thinking I need to define the IP's as an array so say

@personalip = ("x.x.x.x","y,y,y,y")

Now to tell the script that if $ENV{'REMOTE_ADDR'} is one of the IP's in @personlip to exit what would the code be

if following the beginning code which is

#!/usr/bin/perl --

if (!$ENV{'REMOTE_HOST'}) {
$host=$ENV{'REMOTE_ADDR'};
}
else {
$host=$ENV{'REMOTE_HOST'};
}



I was to say
@personalip = ("24.68.24.18","127.0.0.1");

$firstip = shift(@personalip);
$secondip = pop((@personalip);
exit if $host = $firstip;
exit if $host = $secondip;

This didn't work when tested, can someone say what's wrong and is there a much simpler way to code it.



Sponsored Links
  #2  
Old
Closed
 
Join Date: Oct 2000
Location: Australia
Posts: 538
Post

I would just do this:


@ips = ('x.x.x.x', 'y.y.y.y', 'z.z.z.z');

foreach $ip (@ips) {
exit if ($ip eq $ENV{'REMOTE_ADDR'});
}


I think that should do the trick.

  #3  
Old
WHT Addict
 
Join Date: Sep 2000
Posts: 172
Lawrence thanks for trying to help

I put in what you indicated taking out my garbage and I still get an "internal server error".

Do I need to put the info in a specific spot?
I tried where it is below and also directly under @$ips=

The following is the complete script with your recommended addition.


#!/usr/bin/perl --

###############################################################
# Text Counter V1.1
#
# This program is distributed as freeware. We are not
# responsible for any damages that the program causes
# to your system. It may be used and modified free of
# charge, as long as the copyright notice
# in the program that give me credit remain intact.
##################################################################
#
# COPYRIGHT NOTICE:
#
# Copyright 1999-2000 CGI-Factory.com TM
# A subsidiary of SiliconSoup.com LLC
#
#
#
# Text Counter V1.1 is protected by the copyright
# laws and international copyright treaties, as well as other
# intellectual property laws and treaties.
###################################################################
##################################Modify the area below
$invisible ="0";
#set to 1 if you want to counter to be invisible

$noreload ="1";
#set to 1 if you want to block the hit from page reloading
#if you set this variable to 1, remember to upload the file "testrecord.txt"

$flock="y";
###file locking. Don't change it to n unless your system has trouble using file locking.

####################### Nothing more need to be modified below this line unless you feel like to do it

@ips=("24.68.24.18","127.0.0.1");

if (!$ENV{'REMOTE_HOST'}) {
$host=$ENV{'REMOTE_ADDR'};
}
else {
$host=$ENV{'REMOTE_HOST'};
}

foreach $ip (@ips) {
exit if ($ip eq $ENV{'REMOTE_ADDR'});
}

open (count, "<testcount.txt") || &error("Unable to open the data for reading");
if ($flock eq "y") {
flock count, 2;
}
$count = <count>;
close (count);

if ($noreload ==1) {

open (record, "<testrecord.txt") || &error("Unable to open the data file for reading");
if ($flock eq "y") {
flock record, 2;
}
$pvisitor = <record>;
close (record);


open (wrecord, ">testrecord.txt") || &error("Unable to open the data file for writing");

if ($flock eq "y") {
flock wrecord, 2;
}

print wrecord "$host";
close (wrecord);

if ($host==$pvisitor) {
if ($invisible==1) {
print "Content-type: text/html\n\n";
exit;
}
print "Content-type: text/html\n\n";
print "$count";
exit;
}
}
$count++;
open (wcount, ">testcount.txt") || &error("Unalbe to open the data for writing");
if ($flock eq "y") {
flock wcount, 2;
}
print wcount "$count";
close (wcount);

if ($invisible==1) {
print "Content-type: text/html\n\n";
exit;
}
print "Content-type: text/html\n\n";
print "$count";
exit;


sub error{
print "Content-type: text/html\n\n";
print "An error has been occured. The error is: $_[0]<br>\n";
print "$!";
exit;
}


Sponsored Links
  #4  
Old
Closed
 
Join Date: Oct 2000
Location: Australia
Posts: 538
I ran the script on my local machine, and it kept returning a "Premature end of script headers" error. Your best bet is to make sure you've got all the right files there, and the path to perl is correct etc. I don't think it's the script itself.

  #5  
Old
WHT Addict
 
Join Date: Sep 2000
Posts: 172
Counter script

Lawrence thank you for looking at the problem.

I found the needed correction thanks to the help of Owen Prater.

This portion of the code was the culprit

foreach $ip (@ips) {
exit if ($ip eq $ENV{'REMOTE_ADDR'});

Replaced with this

foreach $ip (@ips) {
if ($host eq $ip)
{
print "Content-type:text/html\n\n";
print "$count";
exit;
}
}

a little further down under the first close (count );

This is actually a nifty little counter program for dummies like me as there are no paths to enter and the only variable needed changing would be the IP numbers if someone wanted to make sure the count didn't change when they accesed the site.

If anybody wants the complete version without cutting and pasting from this thread drop me an email.

Reply

Related posts from TheWhir.com
Title Type Date Posted
Service Providers Push Updates to Fight OpenSSL Heartbleed Bug Web Hosting News 2014-05-01 08:31:27
Web Hosting Sales and Promos Roundup - December 6, 2013 Web Hosting News 2014-05-23 15:42:37
Nasuni Launches Cloud Mirroring Feature to Storage Solution Web Hosting News 2013-08-08 14:15:27
OpenStack and the AWS API Debate Web Hosting News 2014-05-09 12:40:29
Pingdom Talks Top Web Hosting Cities and Countries Web Hosting News 2014-05-09 12:40:35


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?