Solved

Foreign GET Query

Posted on 2006-10-23
4
235 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
[X]
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
4 Comments
 

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

626 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