Re: web sniffer
| From: | Jochen Schultz | Date: | Fri, 19 Mar 2010 11:59:29 +0000 |
| Subject: | Re: web sniffer | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303002@lists.php.net to get a copy of this message | ||
Maybe this code may help you getting into it?
<?php
class simpleHttpSocket {
public function sendHttpRequest($host,$filename,$port=80,$timeout=1,$x=0,$result=array()) {
$header = 'GET /'.$filename.' HTTP/1.1'.PHP_EOL;
$header .= 'Host: '.$host.PHP_EOL;
$header .= 'Connection: close'.PHP_EOL;
$header .= 'User-Agent: Simple(php-general@lists.php.net)'.PHP_EOL;
$header .= "Referer: http://test-server.tld/".PHP_EOL.PHP_EOL;
$socket=@fsockopen($host, $port, &$errno, &$errstr, $timeout);
$result[-1]='';
if (!$socket){
trigger_error('Connection timeout',E_USER_NOTICE);
$result["errno"] = $errno;
$result["errstr"] = $errstr;
return $result;
}
fputs($socket, $header);
while (!feof($socket)) {
$result[$x++] = fgets($socket, 128);
if (preg_match('/^Location:/',$result[$x-1])) {
return $result[$x-1];
}
flush();
}
return $result;
}
}
$post = new simpleHttpSocket; $host = 'www.example.com';$filename = ''; // leave empty for index file or else: // $filename = 'image.jpg';
$file = $post->sendHttpRequest($host,$header,80,2);// Output while(list($k,$v)=each($file)) { echo $v.'<br/>'; } ?> regards Jochen madunix schrieb:
can any one give a complete sample script how to retrieve data content from web (jpg, pdf, field). Thanks On Fri, Mar 19, 2010 at 9:53 AM, Jochen Schultz <jschultz@sportimport.de> wrote:-- Sport Import GmbH - Amtsgericht Oldenburg - Tel: +49-4405-9280-63 Industriestrasse 39 - HRB 1202900 - 26188 Edewecht - GF: Michael MüllmannBtw., when you use file_get_contets, is there a good way to tell the script to stop recieving the file after let's say 2 seconds - just in case the server is not reachable - to avoid using fsockopen? regards Jochen madunix schrieb:I've been trying to read the contents from a particular URLokay ..it works now i use <?php $data=file_get_contents("http://www.my.com"); echo $data; ?> On Fri, Mar 19, 2010 at 12:32 AM, Adam Richardson <simpleshot@gmail.com> wrote:On Thu, Mar 18, 2010 at 6:08 PM, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:On Fri, 2010-03-19 at 00:11 +0200, madunix wrote:trying http://us3.php.net/manual/en/function.fsockopen.php do you a piece of code that read parts pages. On Fri, Mar 19, 2010 at 12:00 AM, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:On Fri, 2010-03-19 at 00:03 +0200, madunix wrote:string in PHP, and can't get it to work. any help. Thanks -- If there is a way, I will find one...*** If there is none, I will make one..."*** **************** madunix ******************into a-- Sport Import GmbH - Amtsgericht Oldenburg - Tel: +49-4405-9280-63I agree with Ashley, use one of the other options and then parse the response to get the part of the page you'd like to work with. -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.comI think you're over-complicating things by using fsockopen(). Try one of the functions I mentioned in my last email Thanks, Ash http://www.ashleysheridan.co.ukHow have you been trying to do it so far?There are a couple of ways. file_get_contents() and fopen() will work on URL's if the right ports are open.Most usually though cURL is used for this sort of thing.Thanks, Ash http://www.ashleysheridan.co.uk-- If there is a way, I will find one...*** If there is none, I will make one..."*** **************** madunix ******************Industriestrasse 39 - HRB 1202900 - 26188 Edewecht - GF: Michael Müllmann