Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

redirect to a different page

Hello there,
I have (redir.php) that when you go to it it redirect it to (google.com)

but I would like to add something like this to the code

domain.com/redir.php?GpiiYMZAdL5e
domain.com/redir.php?YdcN6eDAj6xB
domain.com/redir.php?YdcN6eDAj6xB

then you go to (aol.com)


and
domain.com/redir.php?thzNda7aefMo
domain.com/redir.php?hXzRz35YszHA
domain.com/redir.php?PMyU6VXBiMk8

then you go to (yahoo.com)

how can I do this?
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image


Have a code which you put in a variable (say) $extra = "YdcN6eDAj6xB";

Then

header("Location: http://domain.com/redir.php?$extra");
exit;

should do it.
Avatar of XK8ER

ASKER

no i dont think you understood correctly..

if I ask for page (redir.php?hXzRz35YszHA) I want it to redirect me to yahoo

if I ask for page (redir.php?YdcN6eDAj6xB) I want it to redirect me to aol
how I would do it is like this.

Lets say you have a page with 1 link in it.

make the link like this

<a href="redir.php?r=<?=base64_encode("http://www.google.ca")?>">Mystery Site</a>

to the public it would look something like this.
<a href="redir.php?r=aHR0cDovL3d3dy5nb29nbGUuY2E=">Myster Site</a>

then on your redir.php page



<?php
$redir = $_GET['r'];
herader("location:".base64_decode($redir));
?>

Open in new window

Avatar of XK8ER

ASKER

it cant have r=aHR0cDov

it has to be the code only
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually, it should have a default, just incase nothing is passed


<?php

if (isset($_SERVER['QUERY_STRING']) ) {
     switch( $_SERVER['QUERY_STRING']) {
          case "YdcN6eDAj6xB":
                       header ("Location: http://www.aol.com");
                       break;

          case "hXzRz35YszHA":
                       header ("Location: http://www.yahoo.com");
                       break;

          default:
                       break;
     }
}
unfortunately that would only work if you know every link that might be added to the redir.php makes it very static and then pointless to have a redir page.

OK - explain something to me. How you do relate YdcN6eDAj6xB to aol.com? What is the connection?
with my example it uses base64_encode() and base64_decode() so when you create the url you encode the querystring in base64 and on the redir.php you decode it then you have link.

XK8ER:

to use my example without the r=fjasdf do it like this.

<a href="redir.php?<?=base64_encode("http://www.google.ca")?>">Mystery Site</a>

to the public it would look something like this.
<a href="redir.php?aHR0cDovL3d3dy5nb29nbGUuY2E=">Myster Site</a>

then on your redir.php page
<?php
$redir = $_SERVER['QUERY_STRING'];
herader("location:".base64_decode($redir));
?>

Open in new window