For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2008 > Geting the Host from URL in cgi script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Geting the Host from URL in cgi script
Sivasakthi

2008-03-28, 8:01 am

Hi all,

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/block...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?



Thanks,




Gunnar Hjalmarsson

2008-03-28, 8:01 am

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/block...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} ...

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

2008-03-28, 7:04 pm

Gunnar Hjalmarsson wrote:
> sivasakthi wrote:
>
> 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com