Location: PHPKode > scripts > Correct Redirect > correct-redirect/redirect_uri.php3
<?php
/****************************************************************************
Correct Redirect: Redirects your users to the correct page from a webredirect
Author: Shamim Islam
Copyright: Shamim Islam, 2001, all rights reserved
Version: 1.4
Requires: Php v3.0.18 or higher

    This program is free software;you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation;either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY;without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program;if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*****************************************************************************

If you have ever used a redirecting service, you know that the redirect,
regardless of the typed in URL, always goes to the hardcoded URL, unless
you yourself handle the redirecting. Especially when the webredirect is done
in a frame.

*****************************************************************************

E.G.

http://www.myserver.com/testpage.html

using a redirect service goes to

http://realserver.myserver.com/

instead of 

http://realserver.myserver.com/testpage.html

*****************************************************************************

Any attempt to use JavaScript to fix this problem fails usually due to browser
security issues.

The correct method?

*****************************************************************************
include('redirect_uri.php3');
*****************************************************************************
All you have to do is prepend the above statement in your php code
or create a header file that contains the above statement and prepend it
to every page. (Make sure to put php markers around it - it won't work as HTML)

MAKE SURE THIS INCLUDE STATEMENT IS OUTSIDE OF ANY FUNCTIONS AND BEFORE ANY
HEADERS ARE OUTPUT PREFERABLY THE VERY FIRST LINE OF PHP CODE EXECUTED.

All your redirect worries will be fixed. The uri will now cascade to the
redirected url.
*****************************************************************************
Please email hide@address.com if you have any questions with this
script.
*****************************************************************************
Note:
This program is hereby designated GPL and is free for use under those terms.

No removal of copyright or ownership information is allowed.

This script is provided entirely as-is. The author disclaims all liabilities 
direct or indirect that arise from it's use intended or otherwise.
*****************************************************************************
*/

function ____redirect_uri____(){global $HTTP_REFERER,$HTTP_HOST,$REQUEST_URI;if($HTTP_REFERER!=''){$i=&split('/',$HTTP_REFERER);if($HTTP_HOST!=$i[2]){$u=split('/',$REQUEST_URI);reset($u);while(count($i)>3) array_pop($i);if($u[0]=='') each($u);while(list(,$value)=each($u)) $i[]=$value;if(strcmp(ereg_replace('\?$','',$HTTP_REFERER),join('/',$i))!=0){$i=&split('/',$HTTP_REFERER);$i[2]=$HTTP_HOST;Header('Location: '.join('/',$i));exit;}}}}____redirect_uri____();
?>
Return current item: Correct Redirect