fsockopen need help
Moderator: General Moderators
-
realtime158
- Forum Newbie
- Posts: 14
- Joined: Mon Nov 20, 2006 9:09 pm
fsockopen need help
So I am using php version 4.3.9 and lets say i have a file on the server called tester.php
so i am using fsockopen to point to that file but it gives me a error below.
$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno, $errstr, 180);
The tester.php has full permissions
111 Connection refused
This server is linux Redhat Enterprise 2.6.9 with Apache 2.x
Is there anything i need to edit in the php.ini file or apache file.
Thanks for everyone that has helped in advance
so i am using fsockopen to point to that file but it gives me a error below.
$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno, $errstr, 180);
The tester.php has full permissions
111 Connection refused
This server is linux Redhat Enterprise 2.6.9 with Apache 2.x
Is there anything i need to edit in the php.ini file or apache file.
Thanks for everyone that has helped in advance
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Give fsockopen() the domain only. You have to send the other details separately.
What specifically are you trying to accomplish?
What specifically are you trying to accomplish?
-
realtime158
- Forum Newbie
- Posts: 14
- Joined: Mon Nov 20, 2006 9:09 pm
can you give me a
Can you give me a examlple
Thanks...
Thanks...
-
realtime158
- Forum Newbie
- Posts: 14
- Joined: Mon Nov 20, 2006 9:09 pm
thank i got some code but still problem
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
The problem is i can caputre any url except this one http://www.fetchads.com/login/index.php which is on our server. If i change the url to something else it works anything. Would there be something i need to modify on the server. THe server specs are
Redhat Enterprise 2.6.9 with Apache 2.x and php version 4.3.9Code: Select all
<?php
#usage:
$r = new HTTPRequest('http://www.fetchads.com/login/index.php');
echo $r->DownloadToString();
class HTTPRequest
{
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "\r\n";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf
. $crlf;
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]-
realtime158
- Forum Newbie
- Posts: 14
- Joined: Mon Nov 20, 2006 9:09 pm
the reason for this is
I am just working on a screen capture program that will capture the page on our server and email it to one of our clients. That is all
Listen Thanks for all your help by the way. Sometimes its good to get help from the experts. We use to have the ability to do this on our other hosting company with no problems but this is a new server that has been installed and i think there needs to be some settings changed that is all.
Let me know what can i do.
Listen Thanks for all your help by the way. Sometimes its good to get help from the experts. We use to have the ability to do this on our other hosting company with no problems but this is a new server that has been installed and i think there needs to be some settings changed that is all.
Let me know what can i do.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Have you tried using file_get_contents() or cURL?
-
realtime158
- Forum Newbie
- Posts: 14
- Joined: Mon Nov 20, 2006 9:09 pm
i have tried
I have tried cURL and no dice any other ideas?
-
realtime158
- Forum Newbie
- Posts: 14
- Joined: Mon Nov 20, 2006 9:09 pm
here is the code
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Works fine if i try google msn anything else but any php file on my local serverCode: Select all
<?php
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.fetchads.com/login/index.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
// Replace 'Google' with 'PHPit'
//$output = str_replace('Google', 'PHPit', $output);
// Print output
echo $output;
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]