Find the answer to your Linux question:
Results 1 to 8 of 8
With php, our server will capture remote nodes IP addresses like this: <?php echo $REMOTE_IPADDR; ?> But, does anyone know what the newest variables are in RH9 to capture remote_host, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2003
    Location
    Seattle
    Posts
    37

    Info on capturing remote node's address... RH9


    With php, our server will capture remote nodes IP addresses like this:
    <?php

    echo $REMOTE_IPADDR;

    ?>

    But, does anyone know what the newest variables are in RH9 to capture remote_host, remote_addr, etc...?

    I tried the following from a book dated 5 years ago and well, you know how fast the technology stuff changes:

    $remote_address = $ENV('REMOTE_ADDR');
    $remote_host = $ENV('REMOTE_HOST');

    print "IP is: ",$remote_address,"\n";

    and the error message I'm receiving is:

    Error message:
    Global symbol "$remote_address" requires explicit package name

    Anyone know of a simpler way to capture the ip address and host name?

    Thanks.

  2. #2
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Weird, that is the must common Perl errormessage i think. You will recive it if you not have registered you variables or arrays with my first, like

    my $VARIABLE = "something";

    But anyway this is PHP we are talking about, I´m using this one...

    Code:
    $REMOTEIP = getenv&#40;'REMOTE_ADDR'&#41;;

    Regards

    Regards

    Andutt

  3. #3
    Just Joined!
    Join Date
    May 2003
    Location
    Seattle
    Posts
    37
    *
    Here's what I put into place with your pointers w/ exec permissions:

    #!/usr/bin/perl

    //use CGI;
    //use strict;
    //test $cgi=new CGI;

    $REMOTEIP = $getenv('REMOTE_ADDR');
    $REMOTEHOST = $getenv('REMOTE_HOST');
    $REFERRAL_ADDRESS = $getenv('HTTP_REFERER');

    @SUBNET_NUMBERS = split (/\./, $REMOTEIP);
    $PACKED_IP = pack ("C4", @subnet_numbers, 2);

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

    print "<pre>";

    print "Your address is: ", $REMOTEIP, "\n";
    print "Your address is: ", $REMOTEHOST, "\n";
    print "Your address is: ", $REFERAL_ADDRESS, "\n";
    PRINT 'date', "\n";
    print "</pre>";

    exit(0);

    *
    This is the error that follows upon running it from the browser (Nscape & IE 6) Any other suggestions would be appreciated to get this script functioning.

    Server error!
    The server encountered an internal error and was unable to complete your request.
    Error message:
    Premature end of script headers: remote_addr.cgi
    If you think this is a server error, please contact the webmaster
    Error 500
    Thu 01 May 2003 04:31:53 PM PDT
    Apache/2.0.40 (Red Hat Linux)

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Perl? I though you said this was supposed to be PHP? In that case, try adding this to the beginning (after #!/usr/bin/perl, of course):
    Code:
    print "Content-Type&#58; text/plain\r\n\r\n";
    In CGI scripts, you have to manually terminate the HTTP headers, and usually, you will also have to manually output the Content-Type of your output. Considering your output format, I guess this is text/plain rather than text/html. Also note that HTTP uses CR-LF rather than just LF. I'm not really sure if Apache might be doing the conversion for you, though. It was a while since I was doing CGI programming.

  5. #5
    Just Joined!
    Join Date
    May 2003
    Location
    Seattle
    Posts
    37
    Quote Originally Posted by Dolda2000
    Perl? I though you said this was supposed to be PHP? In that case, try adding this to the beginning (after #!/usr/bin/perl, of course):
    Code:
    print "Content-Type&#58; text/plain\r\n\r\n";
    In CGI scripts, you have to manually terminate the HTTP headers, and usually, you will also have to manually output the Content-Type of your output. Considering your output format, I guess this is text/plain rather than text/html. Also note that HTTP uses CR-LF rather than just LF. I'm not really sure if Apache might be doing the conversion for you, though. It was a while since I was doing CGI programming.
    In regards to php, we have no problem capturing the ip addresses (echo $REMOTE_IPADDR) but, the phpinfo() environment didn't provide us with any other ip information capturing variables such as the host, referal, etc...

    Here's what I tweaked with the same failing results. Perhaps someone can catch what we're missing as, I know, it's almost
    #!/usr/bin/perl -Tw


    $REMOTEIP= $getenv('REMOTE_ADDR');
    $REMOTEHOST= $getenv('REMOTE_HOST');
    $REFERAL_ADDRESS= $getenv('HTTP_REFERER');

    @SUBNET_NUMBERS = split (/\./, $REMOTEIP);
    $PACKEDIP = pack ("C4", @SUBNET_NUMBERS);
    ($REMOTEHOST) = gethostbyaddr ($PACKEDIP, 2);

    print "Content-Type: text/plain \r\n\r\n";
    print "<pre>";

    print "Your address is: ", $REMOTEIP, "\n";
    print "Your hostname is: ", $REMOTEHOST, "\n";
    print "You came from: ", $REFEREAL_ADDRESS, "\n";
    print `date`, "\n";
    print "This server: ", `uptime`, "\n";
    print "</pre>";

    exit(0);


    Here's the error message again:

    Server error!
    The server encountered an internal error and was unable to complete your request.
    Error message:
    Premature end of script headers: remote_addr.cgi
    If you think this is a server error, please contact the webmaster
    Error 500
    Thu 01 May 2003 06:21:51 PM PDT
    Apache/2.0.40 (Red Hat Linux)

    Thanks for the assistance..

  6. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Well, first try just this instead:
    Code:
    print "Content-Type&#58; text/plain\n\n";
    Like I said, it's quite possible that Apache wants to do the LF -> CRLF conversion itself, and it's also possible that it considers CRLFs an error condition.

  7. #7
    Just Joined!
    Join Date
    May 2003
    Location
    Seattle
    Posts
    37
    Quote Originally Posted by andutt
    Weird, that is the must common Perl errormessage i think. You will recive it if you not have registered you variables or arrays with my first, like

    my $VARIABLE = "something";

    But anyway this is PHP we are talking about, I´m using this one...

    Code:
    $REMOTEIP = getenv&#40;'REMOTE_ADDR'&#41;;

    Regards


    Well,
    I'm thusfar, stumped. I appreciate you alls help. If anyone catches something I've missed, please reply if you think it will help. Thanks.

  8. #8
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Yoo mtsal

    *
    I also posted this on the forum....
    Here's what I put into place with your pointers w/ exec permissions:
    *Note: because you indicated Linux/Unix programming, I'm hoping you can help. Thanks

    #!/usr/bin/perl

    //use CGI;
    //use strict;
    //test $cgi=new CGI;

    $REMOTEIP = $getenv('REMOTE_ADDR');
    $REMOTEHOST = $getenv('REMOTE_HOST');
    $REFERRAL_ADDRESS = $getenv('HTTP_REFERER');

    @SUBNET_NUMBERS = split (/\./, $REMOTEIP);
    $PACKED_IP = pack ("C4", @subnet_numbers, 2);

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

    print "<pre>";

    print "Your address is: ", $REMOTEIP, "\n";
    print "Your address is: ", $REMOTEHOST, "\n";
    print "Your address is: ", $REFERAL_ADDRESS, "\n";
    PRINT 'date', "\n";
    print "</pre>";

    exit(0);

    *
    This is the error that follows upon running it from the browser (Nscape & IE 6) Any other suggestions would be appreciated to get this script functioning.

    Server error!
    The server encountered an internal error and was unable to complete your request.
    Error message:
    Premature end of script headers: remote_addr.cgi
    If you think this is a server error, please contact the webmaster
    Error 500
    I always program in PHP when im doing webbstuff, and then i should do something like this.

    Code:
    <?php
    session_start&#40;&#41;;
    session_set_cookie_params&#40;0&#41;;
    session_cache_limiter&#40;'private'&#41;;
    ob_start&#40;&#41;;
    
    //Getting BrowserType
    
    $browser   = getenv&#40;'HTTP_USER_AGENT'&#41;;
    $BROWSER   = split&#40;";",$browser&#41;;
    session_register&#40;"$BROWSER"&#41;;
    
    //Getting IP-adress
    $IPADRESS  = getenv&#40;'REMOTE_ADDR'&#41;;
    session_register&#40;"$REMOTE_ADDR"&#41;;
    
    print "Welcome to my site, you are using browser $BROWSER and are surfing from IP $IPADRESS , I see you..\n";
    
    
    ob_end_flush&#40;&#41;;
    ?>
    If you which to use Perl i should do something like this, altough i have never used perl-cgi.

    Code:
    #!/usr/bin/perl
    
    #Register my variables
    #This require that you have a system variable that is called that we are #asking for like SHELL for example
    
    my $IPADRESS=$ENV&#123;'IPADRESS'&#125;;
    my $BROWSER=$ENV&#123;'BROWSER'&#125;;
    
    use warnings;
    use strict;
    
    print "You have Browser&#58;$BROWSER \n";
    print "You have Ipadress;$IPADRESS \n";
    exit 0;
    Hope this will help you on the way...otherwise keep in touch...

    regards

    Regards

    Andutt

Posting Permissions

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