I'm trying to get a remote RSS through proxy and parse it.
I'm using magpierss, but it doesn't allow reaching internet through a proxy (or I don't know how to do it).
I assume the option is to, first, fetch the rss with curl functions, that allows proxy authenticating, but ....
are there any class to do this in a easy way, or ... does magpie support using proxy, and how?
Thanks in advance.
In extlib/Snoopy.class.inc find the following lines:
var $proxy_host = ""; // proxy host to use
var $proxy_port = ""; // proxy port to use
and set there you proxy url and port.
Related
I am working on Application with nodejs and PHP along with Mysql
PHP is frontend here, nodejs is backend
Now
I created a form and while creating a form
i am sending ajax request to Nodejs
like
url: http://example.com:8124/sign_in
Which is working fine
Now Problem is that
When i enabled ssl on Apache.
now i am unable to send request to Node .
it is giving me error, like
Cross-origin policy , load unsafe content
How to resolve this issue
Thanks
That's not a problem with PHP, rather with JavaScript (AJAX). It's because you're trying to load contents from a server that doesn't use SSL from a web page served via SSL.
Simply enable SSL also on the Node app and it will work.
Edit
I do not recommend creating a proxy server in Node.js.
It's actually a good idea to create a proxy server in front of every Node.js app. Indeed, for safety reasons most websites built with Node.js have a Nginx reverse-proxy in front. That is: users connect to Nginx (chosen over Apache for the much better performances) and Nginx makes a request to the Node.js app.
With this setup, you would actually not need to enable SSL in Node.js, as long as Nginx has SSL enabled.
To use SSL directly in Node.js, you need to add just a couple of lines to your app.js file. See this SO question: How do I setup a SSL certs for an express.js server?
If the servers are on the same hostname (just a different port), then you won't need another SSL certificate; if the servers are on a different hostname (e.g. a subdomain) and your SSL certificate isn't a wildcard one, then you will need another certificate.
Speaking about the port... It's true that HTTPS by default runs on 443, but you're free to change it as you want. Just remember to specify it, for example: https://example.com:8443/
A simple way to enable ssl on node is to use a proxy in front of your application:
var fs = require('fs');
var httpProxy = require('http-proxy');
var privateKey = fs.readFileSync('key.pem').toString();
var certificate = fs.readFileSync('cert.pem').toString();
var chainCertificate = fs.readFileSync('ca.pem').toString();
httpProxy.createServer({
target: {
host: 'localhost',
port: ...your application port...
},
ssl: {
key: privateKey,
cert: certificate,
ca: chainCertificate
}
}).listen(...the port for ssl...);
Is it possible to have this setup:
[browser] -> [proxy_1 2.2.2.2:800x (PHP_SCRIPT)] -> [proxy_2 1.1.1.x:8080 (HTTP)] -> [remote server]
I have many proxies like this:
1.1.1.1:8080
1.1.1.2:8080
1.1.1.3:8080
I would like the PHP script to accept incoming connection, and forward it to my real proxies, so that I could simply give out my masked proxies:
2.2.2.2:8080
2.2.2.2:8081
2.2.2.2:8082
Is this possible with PHP sockets? Thanks!
Yes, it is possible. You just need to make sure that your proxy1 will forward the connections to proxy2, and only proxy2 will forward directly the connections. If you want to use PHP sockets you will need to parse HTTP headers and process the entire connection. You could use curl library for this.
Here is a project which uses the proxy concept with curl:
https://github.com/jenssegers/php-proxy
I am currently trying to connect to my elastic search cluster using the php elasticsearch client
I am having trouble using an https endpoint for this. I have my cluster behind a load balancer with a VIP in front, it is using Apache authentication and is on port 443. The trouble I am running into is that the config for the client seems to be parsing the hosts and removes https:// from the host name. this results in the client always trying to connect over port 80. I have tried adding :443 to the host name but I am then getting a curl error "empty reply from server". I know that this server has access (no firewall blocking) because i can manually make the curl call using https://myelasticsearch.com.
My question is, is there a way to specify the protocol to make the request over using this client? if not, where in the source is the parsing of the host array happening?
I have found a temporary solution, in src/Elasticsearch/Connections/AbstractConnection.php there is a defined transportSchema variable that is set to http. I changed this to https and also added the :443 to my host in the config and it works!
Just as an update to this question (in case anyone stumbles into it), this bug was fixed in Elasticsearch-PHP v1.1.0. You can specify https in the host now to use SSL:
$params = array();
$params['hosts'] = array (
'https://localhost', // SSL to localhost
'https://192.168.1.3:9200' // SSL to IP + Port
);
$client = new Elasticsearch\Client($params);
I am currently using PHP to open up a port 43 connection to get whois information directly from a registry using this code.
// connecting to the whois server.
$handle = fsockopen($server, 43);
if (!$handle)
return false; // connection failure
//asking the server
fwrite($handle, $domain_name."\r\n");
// getting response
$response = '';
while (!feof($handle))
$response .= fgets($handle, 1024);
fclose($handle);
It works great however I want to connect though a proxy server so I route my intertent connection through it. If this were able to use cURL I would use curl_setopt($curl_handle, CURLOPT_PROXY, $ip_address . ':4040'); but i can not find a way to do this using fsocketopen. How can I accomplish this either with cURL or fsocketopen()?
Sockets dont have proxy. Just gateways and routers are in-the-middle (if any). You were talking about cURL, that it has proxy - it only uses http/s proxy service. For example, if you have http proxy service on server example.com:8080 you first need to open connection to server example.com (socket) on port 8080 and then send your request, proxy will forward your request and return response. In your case, you just open tcp connection on port 43 on specific host and exchange data directly with target server. If you dont want to do this directly and reveal your ip (or something) you'll need some service too. If you have access to other machine you could use it to do the job. If you want to do it manually you could use ssh or something like that, if you want to make it automatized, you'll probably need to write service on your middle server because you probably wont find any public proxy servers with other protocols than popular http, ftp, ...
Hope this helps.
By the way I see no reason why you should use proxy on whois service.
You could use a SOCKS proxy to relay the TCP connection from your machine to the SOCKS server to the WHOIS server but you would have to implement the SOCKS communication protocol over fsockopen.
Another method would be to use ProxyChains on the server and execute it via PHP. I've answered a similar question here ( How to capture and feed telnet using php and shell scripting? ) which shows how to invoke proxychains from PHP to execute a WHOIS command on a remote server and read the response.
I am trying to load content from a remote URL in my php code. There are two restrictions:
I need to use the dedicated server IP I have so the REMOTE_ADDR of the other server has to be my dedicated IP. This eliminates Curl because Curl uses a proxy to load the remote URL and the proxy changes the IP address which does not work.
I need to load the data on my back-end using PHP. I do not wish to use Javascript for security reasons.
Are there any other solutions other then Curl?
Thank you
What about file_get_contents($url)? Just note that some websites require a user-agent, so you'll have to set one with ini_set() before making the call.
When using the stream api and a wrapper that utilizes the socket-wrapper you can set the bindto context parameter to accomplish (1) :
Used to specify the IP address (either IPv4 or IPv6) and/or the port number that PHP will use to access the network. The syntax is ip:port. Setting the IP or the port to 0 will let the system choose the IP and/or port.
$ctx = stream_context_create( array(
'socket' => array(
'bindto' => '192.168.0.107:0',
)
));
$c= file_get_contents('http://php.net', 0, $ctx);
You could probably use fopen for this.
Have you tried file_get_contents
<?php
$homepage = file_get_contents('http://www.stackoverflow.com/');
echo $homepage;
?>