We help IT Professionals succeed at work.

redirect to a different page

XK8ER
XK8ER asked
on
Medium Priority
1,822 Views
Last Modified: 2008-03-06
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?
Comment
Watch Question

CERTIFIED EXPERT

Commented:

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.

Author

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

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

Author

Commented:
it cant have r=aHR0cDov

it has to be the code only
CERTIFIED EXPERT
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;
     }
}
CERTIFIED EXPERT

Commented:
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;
     }
}

Commented:
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.

CERTIFIED EXPERT

Commented:
OK - explain something to me. How you do relate YdcN6eDAj6xB to aol.com? What is the connection?

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

Explore More ContentExplore courses, solutions, and other research materials related to this topic.