Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with this counter, please...

    Hi,

    I'm new to cgi, and am getting no results with a counter-script that I found in this very forum: ""


    Code:
    #!/usr/bin/perl 
    
    print "Content-type: text/html\n\n"; 
    
    $tempcount = 0; 
    
    while($tempcount < 8) 
    { 
    $tempcount++; 
    if(-e "lock/myfile.lok") 
    { 
    sleep 2; 
    } 
    else 
    { 
    open (LOCK,">>lock/myfile.lok"); 
    close LOCK; 
    open (COUNTER,"<counter.fil"); 
    $count = <COUNTER>; 
    close COUNTER; 
    $count++; 
    open (COUNTER,">counter.fil"); 
    print COUNTER ($count); 
    close COUNTER; 
    unlink "lock/myfile.lok"; 
    last; 
    } 
    }
    ------------------------------------------
    HERE IS MY TEST PAGE:


    Code:
    <html><head><title>_</title></head>
    <body style="background:#ffffff;
    font-face:arial;
    font-size:10px;
    color:#cccccc">
    
    <div style="position:absolute;top:2px;left:5px">
    count = <!--#exec cgi="cgi-bin/counter.cgi"-->
    </div>
    
    <center>
    <br /><br /><br /><br /><br /><br />
    T E S T . . .
    </center> 
    </body></html>
    THESE ARE THE INSTRUCTIONS FROM THE SERVER:
    ------------------------------------------------------

    To use cgi, create a cgi-bin in your home directory. Upload
    .cgi and .pl files into that folder. Remember that they must
    be made executable before they will work.

    Some cgi\'s need a full path name to work. Add /home/username
    to the path name.

    perl version 5 = /usr/local/bin/perl

    -----------------------------------------------------

    THIS IS WHAT i HAVE IN THE CGI-BIN:
    -----------------------------------------------------
    counter.cgi (chmod-755) & counter.fil (chmod-777)

    -----------------------------------------------------
    Nothing is happening with the counter... the page displays ' count = (nothing) ' rather than ' count = # '

    If anyone can see what I am doing wrong, please let me know.
    Last edited by F.N.G.; 02-03-2003 at 12:23 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The same counter works fine for me!

    Your HTML should be something like:-

    <p align="center">You are visitor number <!--#exec cgi="cgi-bin/counter.cgi"--> to this web site</p>

    This will return the counter value at the appropriate point.

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion.

    It didn't actually work for me, though.

    I don't believe the tags & text surrounding the cgi-reference within the html document have any effect on the cgi script itself, so just changing them did nothing.

    There must be some other problem here.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I tried to test your script, and as you say it does not work. It is unclear why - possibly there are some unwanted invisible characters in it. Even spaces after the last } can cause problems. And #!usr/bin/perl must be the very, very first line with no blank lines ahead of it.

    The following DOES work - I have just tested it.

    Make sure that the counter.cgi is CHMOD 755 and counter.fil is CHMOD 777, and in the same directory. Also make sure you have a sub-directory in the cgi-bin called "lock" and that this directory is CHMOD 777.

    #!/usr/bin/perl

    print "Content-type: text/html\n\n";

    $tempcount = 0;

    while($tempcount < 8)
    {
    $tempcount++;
    if(-e "lock/myfile.lok")
    {
    sleep 2;
    }
    else
    {
    open (LOCK,">>lock/myfile.lok");
    close LOCK;
    open (COUNTER,"<counter.fil");
    $count = <COUNTER>;
    close COUNTER;
    $count++;
    open (COUNTER,">counter.fil");
    print COUNTER ($count);
    close COUNTER;
    unlink "lock/myfile.lok";
    print $count;
    last;
    }
    }



    Try pasting this and uploading it to your own cgi bin. Do not select anything before the first (#) or after the final character (}).

    Best of luck! But this simple script ought not to give headaches!
    Last edited by Philip M; 02-04-2003 at 08:03 PM.

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I'll give that a try...

  • #6
    New Coder
    Join Date
    Jan 2003
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    It worked; thank very much for your help.

    (I was also unaware that the document needed to be given a ".shtml" extension... is that a universal truth, or server specific?)

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    253
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many servers require the shtml extension on pages if it contains an SSI command. Some others are more relaxed and allow other extensions to be parsed. If you have the ability to use your own ".htaccess" file, then you can also change the ability over to html extensions.

  • #8
    New Coder
    Join Date
    Jan 2003
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, thanks.


  •  

    Posting Permissions

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