Php get url proxy

Building a ‘simple’ php url proxy

Here are my cURL setopts: outputs Failed connect to ######.com:8080; No error Where 100.100.100.100:8080 is a placeholder for a valid HTTPS proxy. You can access the proxy through https, effectively encrypting all your traffic between your computer and the VPS.

Building a ‘simple’ php url proxy

I need to implement a simple PHP proxy in a web application I am building (Its flash based and the destination service provider doesn’t allow edits to their crossdomain.xml file)

Can any php gurus offer advice on the following 2 options? Also, I think, but am not sure, that I need to include some header info as well.

$url = $_GET['path']; readfile($path); 
 $content .= file_get_contents($_GET['path']); if ($content !== false) < echo($content); >else < // there was an error >

First of all, never ever ever include a file based only on user input. Imagine what would happen if someone would call your script like this:

Then onto the issue: what kind of data are you proxying? If any kind at all, then you need to detect the content type from the content, and pass it on so the receiving end knows what it’s getting. I would suggest using something like HTTP_Request2 or something similar from Pear (see: http://pear.php.net/package/HTTP_Request2) if at all possible. If you have access to it, then you could do something like this:

// First validate that the request is to an actual web address if(!preg_match("#^https?://#", $_GET['path']) < header("HTTP/1.1 404 Not found"); echo "Content not found, bad URL!"; exit(); >// Make the request $req = new HTTP_Request2($_GET['path']); $response = $req->send(); // Output the content-type header and use the content-type of the original file header("Content-type: " . $response->getHeader("Content-type")); // And provide the file body echo $response->getBody(); 

Note that this code hasn’t been tested, this is just to give you a starting point.

Here’s another solution using curl Can anyone comment??

$ch = curl_init(); $timeout = 30; $userAgent = $_SERVER['HTTP_USER_AGENT']; curl_setopt($ch, CURLOPT_URL, $_REQUEST['url']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); $response = curl_exec($ch); if (curl_errno($ch)) < echo curl_error($ch); >else

PHP proxy to get XML: problem with URL arguments, Otherwise your web server and PHP will get very confused about which bit of your URL is the URL for the proxy service, and which bit is the URL that you want to go get data from. The solution from the Flash side probably depends on how you’re doing the call at the moment.

How to make a proxy using a php script?

Let’s say i got a vps hosting with a dedicated ip, can i make a curl php script that receives a url, fetch it, and output it, and make all this as a proxy server, so i can put my vps ip in the proxy settings of the browser.

Is there any way to do that?

Читайте также:  And operator string python

Note: Please don’t suggest me a web based proxy like glype.

Yes, you could (see Jasper’s answer). That would be effectively making your own web-based proxy.

However, given that it’s a VPS, I would suggest using a SSH SOCKS proxy, since it’ll be easier and will be running through an encrypted tunnel to the VPS.

Use Apache with mod_proxy and mod_proxy_http . See the docs.

You can access the proxy through https, effectively encrypting all your traffic between your computer and the VPS.

You can use tor proxy, here is the script:

Call the function » if (tor_new_identity(‘127.0.0.01’, ‘9051’)) » But you must install the tor system in the VPS 1st.

You’re wrong at what are you asking. You ask about PHP script, but don’t like the Glype. There are at least 4 more PHP’s proxy developments.

  1. GlypeProxy, the most known PHP proxy. Does cURL.
  2. Poxy, i discover it recently, love. Uses client/server sockets.
  3. php-proxy, but there are few ones that shares that name // too basics

But in fact, no one will let you connect your browser with it, because you need to implement the tcp wrapper for the connection. This is the way you got usually an http interface with cURL or direct raw socket.

You need an SO app, not an script.

I would recommend you Squid proxy for Linux (handy and clean manual http://es.kioskea.net/faq/613-instalar-un-servidor-proxy-http-squid) I would recommend you to not use Windows (even if i do), but the FreeProxy is awesome. (download at http://www.softpedia.com/get/Internet/Servers/Proxy-Servers/FreeProxy.shtml)

On the other hand of the proxy, you got the VPN. It’s better and easier to install and connect to a VPN, a private SSH protected private network to your VPS. That will bypass ALL the traffic from your computer through a encrypted connection to/from the VPS.

You will have the VPS’s IP, and «local» connectivity to your VPS/Desktop from both sides. (example, web servers with no need of open ports except the VPN one)

How do I use my server as a proxy to download files via, I need my server to act as a proxy between a 3rd party server (where the file is originally located) and the end user. That is, my server downloads the file from the 3rd party server, and sequentially, the user downloads it from my server. This should result in an incurred bandwidth of twice the file size. How can this …

PHP connect to HTTPS site through proxy

I’ve got the following problem: there is an HTTPS web site, and I need to connect to it through a proxy. Here are my cURL setopts:

curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_PROXY, '100.100.100.100:8080'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $ua); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); echo curl_error($ch); 

outputs Failed connect to ######.com:8080; No error

Читайте также:  Проверка всего массива java

Where 100.100.100.100:8080 is a placeholder for a valid HTTPS proxy. This doesn’t work. How do I make cURL connect to an HTTPS website through a proxy? I would really like a soultion that would work through not only HTTPS proxies. Also, I would best prefer a method using cURL, but if there is a better way to do it, without cURL, I could use it instead.

Update: Add

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 

It will prevent your HTTP proxy to parse your request headers and to act more transparently — like a tunnel.

initial answer, not interesting

Your code looks OK, and I assume you checked the trivial issues, so the problem is probably that the SSL certificate verification fails. It’s the case if the certificate is self signed by example. Try

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

to allow a request that allows using a self signed certificate.

Jquery — How to use PHP proxy for CORS?, In your client side js you set the request header as ‘X-Proxy-URL’:, however, in your server-side php you check for ‘X-Proxy-Url’, notice the URL vs Url part. Share. Follow answered Oct 6, 2016 at 6:51. lightxx lightxx. 1,017 2 2 gold badges 11 11 silver badges 27 27 bronze badges.

How can I find an application’s base url behind a proxy?

Our PHP-based application (custom made, no framework) sometimes needs to use its base full URL (for instance to store URL in files send to clients). Based for instance on this question, our application guess this (this is based on comparing __FILE__ and various variables in $SERVER like SCRIPT_NAME and SERVER_NAME ).

Now we need to setup a (nginx) reverse-proxy in front of our application. Suppose that we map https://example.com/some/dir/onproxy/ to http://backend/another/dir/onbackend/ .

Is there a way to guess the public URL ( https://example.com/some/dir/onproxy/ ) from the code on backend ?

AFAIU (from my readings and experiments), it’s not possible ( HTTP_HOST may give example.com but I have found nothing that indicates some/dir/onproxy ) but maybe I’m missing something (some variables or a nginx configuration option).

In case it’s not possible, the only solution is to store https://example.com/some/dir/onproxy/ in the configuration, right ?

As suggested by @Progman, I tried solutions on this question. I have tried both the accepted answer and the second most upvoted answer but both return (some variation of) the URL on the backend ( http://backend/another/dir/onbackend/ ).

I forgot to mention that I would like to avoid to rely on URL rewriting in the proxy.

Читайте также:  Открытие документа в python

Since Nginx is changing the request before it reaches the PHP backend, the solution is to add the original request data in somehow to the proxied request.

A common used convention for this is to add the original data in as extra HTTP headers. See X_Forwarded_For as an example of this.

To add the original request path as a new header, add a proxy_set_header directive to Nginx.

Something similar to that in your configuration will proxy the original request to a PHP web server on the back end. It does assume the backend is a HTTP server and not PHP-FPM.

Within PHP the quickest way to get the value of a single HTTP header is via $_SERVER. The original request path will be in $_SERVER[‘HTTP_X_REQUEST_URI’] .

This is just an example, you may need to test and debug your application to refine the solution. php_info(); is a useful debug tool for the PHP environment, however it would also be useful to malicious actors so remove from your code as soon as possible or take other measures to ensure it is not exposed.

PHP image proxy to use direct URL instead?, Teams. Q&A for work. Connect and share knowledge within a single location that is structured and easy to search. Learn more

Источник

Использование curl в php через прокси

Компьютерное

Бывает так, что нужно работать в php с библиотекой curl для обращения, например, к какому-либо API сервиса. И бывает очень неприятно, когда доступ к API оказывается заблокирован для вашего сервера по IP. Выпутаться из данной ситуации можно перенаправляя запросы сервера через прокси. Это можно делать через системные настройки, засылая ВСЕ запросы через прокси-сервер либо выполняя именно те запросы, которые вам требуются.

В принципе всё просто. У вас есть запрос:

$url = "http://www.example.com/API/v2.0/"; function get_url($url) < $ch = curl_init(); if($ch === false) < die('Failed to create curl object'); >$timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); return $data; > echo get_url($url);

Вам потребуется изменить запрос:

$url = "http://www.example.com/API/v2.0/"; function get_url($url) < $proxy_ip = 'your_proxy_ip:proxy_port'; //IP адрес сервера прокси и порт $loginpassw = 'login:password'; //логин и пароль для прокси $ch = curl_init(); if($ch === false) < die('Failed to create curl object'); >$timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //Указываем к какому прокси подключаемся и передаем логин-пароль curl_setopt($ch, CURLOPT_PROXY, $proxy_ip ); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw); //доступные значения для типа используемого прокси-сервера: CURLPROXY_HTTP (по умолчанию), CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A или CURLPROXY_SOCKS5_HOSTNAME. curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); $data = curl_exec($ch); curl_close($ch); return $data; > echo get_url($url);

Из комментариев к коду, я думаю и так понятно что изменилось и какие значения следует использовать. Надеюсь у вас всё получится 😉

Источник

Оцените статью