Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Foreign GET Query

Posted on 2006-10-23
4
217 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkout Page Input Field not aligned 1 26
hbo knew my windows software 4 60
how to call a remote wordpress to use his  content in a loop 3 32
php help 34 58
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

809 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