0

Is there a way to setup a proxy over URL Parameters? The script should run on a Ubuntu Server. Or is it possible to make this done with squid or something similar?

Like http://proxyserver.com:3128/http://google.de

I already tried some PHP proxy scripts but it's not realy working with it. It should open a file as a stream but with some scripts load the whole file and then I get an output or it doesn't work with Safari and on every browser I got bugs with javascript to get information of the stream.

Probably this helps, why it isn't working on safari. I don't know how can i edit the headers more. Accept-Ranges etc is set

Kim Schaper
  • 11
  • 1
  • 5

3 Answers3

0

Another Edit

Try this code here. Post is implemented.

$url = $_GET["url"];
$method = $_SERVER["REQUEST_METHOD"];
$data = array($_POST);
$options = array(
  "http" => array(
    "header"  => "Content-type: application/x-www-form-urlencoded\r\n",
    "method"  => $method,
    "content" => http_build_query($data),
  ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$filter = "/(http|https|ftp|ftps)(:\/\/)/i";
$result = preg_replace($filter, "http://YOURDOMAIN.com/FOLDER/LOCATIONOFTHEPROXY.php?url=$1$2", $result);
echo $result;
var_dump($result);

EDIT

Here I found some code to POST using PhP. Only got to implement it now.

<?php
$url = "url to post to;
$data = array("comment" => "Testing PhP Post", "name" => "A PhP Script");
// use key "http" even if you send the request to https://...
$options = array(
  "http" => array(
    "header"  => "Content-type: application/x-www-form-urlencoded\r\n",
    "method"  => "POST",
    "content" => http_build_query($data),
  ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
echo $result;
var_dump($result);
?>

Have you tried file_get_contents()?

Try this:

<?php
  echo file_get_contents($_GET["url"]);
?>

Call the file with the query like ?url=http://google.com/.

Community
  • 1
  • 1
  • Oops! It's `file_get_contents`, not `get_file_contents`. –  Feb 23 '16 at 23:28
  • Does your PhP/server/hosting allow you to request arbitrary pages (files outside of your domain/send a request to a server)? –  Feb 23 '16 at 23:33
  • No, it works but it don't work how i need. This for example "downloads" the whole file and then outputs it. I tried it with fopen streams, too. On Browsers like Firefox it works but on Safari not really. Javascript/jQuery functions on any have bugs cause on this way so i can't use it anyway The Problem is the main script makes a POST and get an URL to a file, the the File URL is assigned to the IP address. So i can't integrate the direct link on the website and cross domain POSTS with jQuery don't work, too – Kim Schaper Feb 23 '16 at 23:49
  • [@KimSchaper](http://stackoverflow.com/questions/35590131/url-parameter-proxy-script/35590281?noredirect=1#comment58867395_35590281) Okay. There is a way to use post requests. I haven't exactly nailed it yet though... –  Feb 24 '16 at 00:36
  • [@KimSchaper](http://stackoverflow.com/questions/35590131/url-parameter-proxy-script/35590281#comment58868387_35590281) I updated the post with a proxy that works. The only problem is that it doesn't parse relative urls. –  Feb 24 '16 at 01:24
  • I'm sorry if i'm not able to explain it good enough, because my english ist not the best. – Kim Schaper Feb 24 '16 at 01:44
  • The Post is not the Problem. POST from server -> get file url from response (This works already) Problem: Can't include file url in website cause cause if the browser loads the file,the browser loads it with the user IP (1.1.1.1) and not the IP(2.2.2.2) of the Server with which the post was made and the file url was bound with. – Kim Schaper Feb 24 '16 at 01:50
  • @KimSchaper The third last line of code is replacing all the absolute urls (protocol://domain.com/file) but not the relative ones (/file). Try changing all your relative ones to absolute. –  Feb 24 '16 at 02:10
0

If you want a php proxy to start with, you should go with Glype Proxy

Plus, your URL http://proxyserver.com:3128/http://google.de is invalid and considered malformed URL.

To fix it you have to escape the other URL (with a query sting or so). e.g. $URL_in_PHP = "http://proxyserver.com:3128/?url=".urlencode('http://google.de');

var URL_in_javascript = "http://proxyserver.com:3128/?url="+encodeURI('http://google.de');

and tell your proxy server to navigate to$_GET['url']

Em Seven
  • 155
  • 1
  • 1
  • 10
0

I solved it.

I used a nginx server with proxy_pass parameter

Kim Schaper
  • 11
  • 1
  • 5