Re: function to variable?

From: Date: Fri, 19 Jul 2002 19:53:49 +0000
Subject: Re: function to variable?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-108568@lists.php.net to get a copy of this message
Hi Jas, I may be missing something here, but it looks as though you just need to return() your $msg var and assign it in your main script. So, something like: function arin($ipaddy) { $server = "whois.arin.net"; . . . return $msg; } <?php $whois = arin($ipaddy); $sql = "INSERT INTO www_access (whois) ('".addslashes($whois)."')"; mysql_query($sql); ?> HTH, Hans On Fri, 2002-07-19 at 15:52, Jas wrote: > Not sure how to accomplish what I would like to, I recently downloaded and > installed a small Network tool from http://www.shat.net and I > only need the > results of one of the functions included to be passed as a variable to an > input command for mysql. Here is the code, any help is appreciated! > Jas > <?php > /* Check client info and register */ > if (getenv(HTTP_X_FORWARDED_FOR)){ > $ipaddy = getenv(HTTP_X_FORWARDED_FOR); > } else { > $ipaddy = getenv(REMOTE_ADDR); > $host = gethostbyaddr($REMOTE_ADDR); } > > /* Start looking up users IP vs. WHOIS database for logging */ > $nipaddy = ""; > function message($msg){ > echo "<font face=\"verdana,arial\" size=2>$msg</font>"; > flush(); > } > function arin($ipaddy){ > $server = "whois.arin.net"; > message("<p><b>IP Whois Results:</b><blockquote>"); > if (!$ipaddy = gethostbyname($ipaddy)) > $msg .= "Can't IP Whois without an IP address."; > else{ > message("Connecting to $server...<br><br>"); > if (! $sock = fsockopen($server, 43, &$num, &$error, 20)){ > unset($sock); > $msg .= "Timed-out connecting to $server (port 43)"; > } > else{ > fputs($sock, "$ipaddy\n"); > while (!feof($sock)) > $buffer .= fgets($sock, 10240); > fclose($sock); > } > if (eregi("RIPE.NET", $buffer)) > $nextServer = "whois.ripe.net"; > else if (eregi("whois.apnic.net", $buffer)) > $nextServer = "whois.apnic.net"; > else if (eregi("nic.ad.jp", $buffer)){ > $nextServer = "whois.nic.ad.jp"; > #/e suppresses Japanese character output from JPNIC > $extra = "/e"; > } > else if (eregi("whois.registro.br", $buffer)) > $nextServer = "whois.registro.br"; > if($nextServer){ > $buffer = ""; > message("Deferred to specific whois server: > $nextServer...<br><br>"); > if(! $sock = fsockopen($nextServer, 43, &$num, &$error, 10)){ > unset($sock); > $msg .= "Timed-out connecting to $nextServer (port 43)"; > } > else{ > fputs($sock, "$ipaddy$extra\n"); > while (!feof($sock)) > $buffer .= fgets($sock, 10240); > fclose($sock); > } > } > $buffer = str_replace(" ", "&nbsp;", $buffer); > $msg .= nl2br($buffer); > } > $msg .= "</blockquote></p>"; > message($msg); > } > ?> > As of yet I have only been echoeing the results to the screen like: > <?php echo arin($ipaddy) ?> Which works, but I do not want the results > output to the screen for the view, I would like to assign a variable like > $whois to the results of this function so I may stick it in the database for > later retrieval. Any help on this would be great! > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#108568) next »