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?
LVL 1
XK8ERAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Beverley PortlockConnect With a Mentor Commented:
OK, At the start of redir.php, put this code

<?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;
     }
}
0
 
Beverley PortlockCommented:

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.
0
 
XK8ERAuthor Commented:
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
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nplibCommented:
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

0
 
XK8ERAuthor Commented:
it cant have r=aHR0cDov

it has to be the code only
0
 
Beverley PortlockCommented:
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;
     }
}
0
 
nplibCommented:
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.

0
 
Beverley PortlockCommented:
OK - explain something to me. How you do relate YdcN6eDAj6xB to aol.com? What is the connection?
0
 
nplibCommented:
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

0
All Courses

From novice to tech pro — start learning today.