Solved

Foreign GET Query

Posted on 2006-10-23
4
211 Views
Last Modified: 2006-11-18

is there a way to query a foreign php page without cURL like the following pseudo code?

$ip = 'xxx.eee.www.qqq';

$lookup="http://aaa.zzzz.yyyy/country.php?ip='$ip'";


..and have the value stuck inside $lookup?

maybe im off base here, but i thought there was a less involved way than using cURL ...

anyone?
0
Comment
Question by:n8dog
4 Comments
 
LVL 5

Expert Comment

by:daohailam
ID: 17793159
0
 

Author Comment

by:n8dog
ID: 17793690
interesting... got some sample applicable syntax?

0
 
LVL 9

Accepted Solution

by:
tolgaong earned 500 total points
ID: 17794359
first and second method needs allow_url_fopen true as ini set
third method can get all the data although allow url fopen false...
$lookup="http://aaa.zzzz.yyyy/country.php?ip='$ip'";

//FIRST
$firstbuffer="";
$html=fopen($lookup,"rb");
while(!feof($f)){
   $firstbuffer.=fread($f,4096);
}
fclose($f);

//SECOND
$secondbuffer=file_get_contents($loopkup);

//THIRD
if(preg_match("/^http:\/\/([^\/]+)(.*)$/", $lookup, $matches)){
         $response ="";
         $thirbuffer = '';
         $host = $matches[1];
         $uri = $matches[2];

         $request = "GET $uri HTTP/1.0\r\n";
         $request .= "Host: $host\r\n";
         $request .= "User-Agent: Mozilla \r\n";
       $request .= "Connection: close\r\n\r\n";

         if($http = fsockopen($host, 80, $errno, $errstr, 5)){
                fwrite($http, $request);
                $timeout = time() + 5;
                while(time() < $timeout && !feof($http)) {
                    $response .= fgets($http, 4096);
                      }
                list($header, $thirbuffer) = preg_split("/\r?\n\r?\n/", $response, 2);                  
               }
      }
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question