Hello, i would like to change a php proxy. right now it uses. "fsockopen". but with this function you are not able to bind it to another ip on the server, it just uses the "default" (first) ip. and i would like to use several IPs from the same server (outgoing ips)
this function here is able to bind to a socket and i would like to include this in the php proxy source, but i fail 🙂 if someone could help me, that would be great.
$opts = array(
'socket'=>array(
'bindto'=>'64.255.0.135:41000' //any port will do
)
);
$context = stream_context_create($opts);
$html = file_get_contents('http://www.ipchicken.com/', false, $context);
echo $html;
?>
code from the php proxy:
function start_transfer($url)
{
$this->set_url($url);
$this->open_socket();
$this->http_basic_auth();
$this->set_request_headers();
$this->set_response();
$this->http_basic_auth();
}
function open_socket()
{
$this->socket = @fsockopen($this->url_segments['host'], $this->url_segments['port'], $err_no, $err_str, 12);
if ($this->socket === false)
{
$this->trigger_error("$err_no: $err_str (URL: {$this->url_segments['host']})", encode_url($this->url));
}
}
function set_response()
{
fwrite($this->socket, $this->request_headers);
// Reset response headers and response body.
$this->response_headers = '';
$this->response_body = '';
// Get the response headers first to extract content-type.
do
{
$line = fgets($this->socket, 4096);
$this->response_headers .= $line;
}
while ($line != "\r\n");
$this->response_code = next(explode(' ', $this->response_headers));
$this->set_content_type();
$this->set_content_length();
if ($this->flags['accept_cookies'] == 1)
{
$this->set_cookies();
}
if ($this->follow_location())
{
fclose($this->socket);
$this->start_transfer($this->url);
}
else
{
// If content-type isn't html or xhtml, just dump the rest of the response back to the client since
// we don't need to do any further operations on it. And if the file were like a large movie file, it
// wouldn't fit in a variable without exceeding the memory limit alloted for the scipt.
if (!in_array($this->content_type, array('text/html', 'application/xml+xhtml', 'application/xhtml+xml', 'text/css')) && (!$this->content_length || (int)$this->content_length <= $this->config['max_file_size']))
{
// Impose no time limit since it might be a large file that would take a long while to download.
@set_time_limit(0);
$this->send_response_headers();
fpassthru($this->socket);
fclose($this->socket);
exit();
}
// Read the HTML response in $this->response_body
do
{
$data = fread($this->socket, 8192);
$this->response_body .= $data;
}
while (strlen($data) != 0);
fclose($this->socket);
}
}