Redirect Traffic Using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shackles
Forum Newbie
Posts: 3
Joined: Tue Sep 03, 2013 11:53 am

Redirect Traffic Using PHP

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Redirect Traffic Using PHP

Post 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.
shackles
Forum Newbie
Posts: 3
Joined: Tue Sep 03, 2013 11:53 am

Re: Redirect Traffic Using PHP

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Redirect Traffic Using PHP

Post 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.
shackles
Forum Newbie
Posts: 3
Joined: Tue Sep 03, 2013 11:53 am

Re: Redirect Traffic Using PHP

Post by shackles »

Ok.

And if i dump $_SERVER, i get an array error.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Redirect Traffic Using PHP

Post by requinix »

"Array"? You can't just echo/print it. Use var_dump or print_r.
Post Reply