PHP redirect plus masking.

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
James01
Forum Newbie
Posts: 1
Joined: Tue Sep 28, 2010 11:37 pm

PHP redirect plus masking.

Post by James01 »

Hi

Well I have been using a php redirect script where I create a new folder and in the folder paste a index.php file which contains the code for a redirect.

For example http://DomainName/Sub redirects to http://www.yahoo.com using the following code

Code: Select all

<?php
header( 'Location: http://www.yahoo.com' );
?>
First Question:- Is there a way to do it quickly instead of every time having to create new folders and then creating an index file in them?

Second Question:- What code should I insert in the above so that when someone gets redirected he still sees http://DomainName/Sub

I look forward to the help.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: PHP redirect plus masking.

Post by twinedev »

Question 1, to do it automatically.

Look into using mod_rewrite so that when people go to a place on your server, if it isn't an actual file (or folder), then it will fire a specific script and be passed the actual called page.

Then that script could then take what was actually browsed for, look it up in a database to see where you wanted to redirect them to.

(Sorry, been a long day, to tired to get into details, just giving basics for now).

Question 2, do it and keep the URL the same.

Two methods, one simple, one not so simple.

-Simple method, do a frame, 100%, and call the other page as the source of the frame.
-Complex, write code that does something like curl to grab the source of the page you are wanting them to see. Then you also have to handle the fact that all referenced images/CSS/javascript are on the other server. Also, as soon as they follow a link, unless you mask ALL links as well, you use the URL in the browser.

NOTE: For quest #2, it is recommended that you only do this with sites you have permission to do this with. (ie, I'm sure it was just a sample, but if you were to do this with Yahoo's site, and they find out you are feeding their content as your own domain, they may not like it and you may get a C&D from their (not so) friendly legal henchmen.

-Greg
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: PHP redirect plus masking.

Post by DigitalMind »

Q2. mod_proxy is also able to solve it
Post Reply