Re: Geting the Host from URL in cgi script



Gunnar Hjalmarsson wrote:
sivasakthi wrote:
I have passed the one URL to cgi script , and i have retrieve the values
by using the param method..
the example url is following ,

http://172.16.2.30:2004/block/blocked.cgi?url=google.com&target=gambling

now i wanted to retrieve the host of
http://172.16.2.30:2004/block/blocked.cgi .. how i can able to get that?

my $hostname =
( gethostbyaddr pack('W4', split /\./, '172.16.2.30'), 2 )[0];

Or maybe you are simply looking for the CGI variable $ENV{HTTP_HOST} ...

Or do you just want

my ($host) = $uri =~ m#://(.+?)[:/]#;

Your initial post leaves room for various interpretations. :)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: editing perl script through TEXTAREA
    ... Xho and gnari discussed a fictitious ... > param(), so there is no 'reverse' convertion as such, but the fact ... people who use CGI scripts gain a basic understanding and insight ... Gunnar Hjalmarsson ...
    (comp.lang.perl.misc)
  • Re: URI::URL
    ... > Those links I store in URI objects, which I collect in a large ... > In the vey beginning it would not even allow me to call the host() ... > that I pass in some invalid argument, for ex an invalid URL so that ... Gunnar Hjalmarsson ...
    (comp.lang.perl)
  • Re: how many days ago is 2003-07-20 ?
    ... Gunnar Hjalmarsson wrote in comp.lang.perl.misc: ... > Marcus wrote: ... >> Can someone pls show the most solid way in perl to retrieve the ...
    (comp.lang.perl.misc)
  • Re: Redirecting to another url with parameters using post method
    ... redirect. ... what CGI::redirect prints AFAIK)? ... Gunnar Hjalmarsson ...
    (perl.beginners)
  • Re: Redirecting to another url with parameters using post method
    ... On 08/25/2007 04:32 PM, Gunnar Hjalmarsson wrote: ... redirect. ... what CGI::redirect prints AFAIK)? ...
    (perl.beginners)