Page 1 of 1

Redirect Traffic Using PHP

Posted: Tue Sep 03, 2013 12:03 pm
by shackles
Hi there I am trying to do this:

Open on Machine A (http://www.google.com) which will send the petition Machin B with a apache server instead of the Router, then Machine B sends back http://www.google.com to the Machine A.

Its nearly like a proxy.

I dont want to use any proxy program because this way I cant put in my own adverts or headers (like anonymouse for example).

For example on my machine

192.168.1.2 I want to open Google (My navigator is linked to 192.168.1.3:80 by proxy settings).
On 192.168.1.3 I have Apache Running.

I have tried like this:

Code: Select all

<html>
<?php
$test2 = "http://";
$test = $_SERVER["HTTP_HOST"];
$test3 = $test2 + $test;
$newVar = "$test2$test";
echo '<iframe src="'.$newVar.'" />';
?>
</html>
And this:

Code: Select all

<html>
<?php
header('Location: '.$_SERVER["HTTP_HOST"].'');
?>


But they just go into a loop obviously, but I dont know how to do this.


In other words, I want to do a proxy for when it is used I can use my own adverts etc.
I have tried using proxy servers, but you cant manipulate the traffic to put your own code in it.

Thanks.

Re: Redirect Traffic Using PHP

Posted: Tue Sep 03, 2013 1:32 pm
by requinix
I don't know of any Apache way to make it proxy through a script, but you can just RewriteRule everything through a PHP script. Proxy requests are basically just special HTTP requests.

Code: Select all

RewriteEngine on
RewriteRule ^ proxy.php [L]
Try dumping out $_SERVER to see what you get.

Re: Redirect Traffic Using PHP

Posted: Tue Sep 03, 2013 2:00 pm
by shackles
Proxy is easy to setup, but I need to manipulate the output.

I have tried with rewrite rules, no luck with that.

What you mean by dump, echo or printing it?

Re: Redirect Traffic Using PHP

Posted: Tue Sep 03, 2013 2:33 pm
by requinix
And what I'm saying is you'd have to write some PHP to manipulate the content. Because Apache can't.

Yes, by "dump out" I mean output. Or whatever it takes to let you see the data.

Re: Redirect Traffic Using PHP

Posted: Tue Sep 03, 2013 3:17 pm
by shackles
Ok.

And if i dump $_SERVER, i get an array error.

Re: Redirect Traffic Using PHP

Posted: Tue Sep 03, 2013 3:37 pm
by requinix
"Array"? You can't just echo/print it. Use var_dump or print_r.