Results 1 to 5 of 5

Thread: script help

  1. #1
    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.

  2. #2
    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. #3
    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;
    }


  4. #4
    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. #5

    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.

  6. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •