[COLUG] PHP Question

Duane duane at e164.org
Wed Nov 14 07:11:00 EST 2007


Rob Robson wrote:
> Working on a PHP web page to get IP information into a variable and mail it back to me.  Having a problem 
> getting the whois data into the variable.
> 
> This line works Okay
> $ip = getenv("REMOTE_ADDR");   
> 
> This only returns one word or the last line of the lookup.
> $message = exec ('/usr/bin/whois "$ip"');
> 
> How do I get the complete whois info into $message ???

Unless you *KNOW* what you are doing, don't even bother trying to wrap
unsanitised text in quotes, it's a waste of time, *ALWAYS ALWAYS ALWAYS*
use escapeshellarg(), in this case it's not as imperative until there is
a bug in your web daemon that can in turn exploit PHP :)

$ip = escapeshellarg($_SERVER['REMOTE_ADDR']);

Then just use back ticks. trim() is optional.

$whois = trim(`whois $ip`);

-- 

Best regards,
 Duane

http://www.freeauth.org - Enterprise Two Factor Authentication
http://www.nodedb.com - Think globally, network locally
http://www.sydneywireless.com - Telecommunications Freedom
http://e164.org - Because e164.arpa is a tax on VoIP

"In the long run the pessimist may be proved right,
    but the optimist has a better time on the trip."


More information about the colug432 mailing list