• 0

Redirect PHP script?


Question

Hey guys,

 

I used to have (and can't find it anymore) a script years ago that I need again that does redirection.

Example: website.com/redirect.php?4043

 

4043 would be a URL in a file like links.txt that the script would reference.

It's like how Microsoft used to use on their site years ago.

 

Does anyone know where I can something like this?

 

Much appreciated!

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

You mean something like this:

 

domain.com/page/?redirectid=6 

 

that will take the user to the page based on id, is what you want?

 

If so, you can use either make it up or get the already-made redirect script.

 

make it up means you can write on your own, something like this:

if $redirectid == "404" 

code goes here based on id such as 404 as mentioned above.

if $redirectid == "500"

place code here based on id... 


Link to comment
Share on other sites

  • 0

Thanks for the responses, I could write it I suppose, but i'd rather have something ready made.

Anyone know of one?

Link to comment
Share on other sites

  • 0

Well I wasn't able to find what I wanted, so I wrote it up.

Here you all go if you need it:

 

<?php

$links = parse_ini_file('urllist.txt');

if(isset($_GET['go']) && array_key_exists($_GET['go'], $links)){
    header('Location: ' . $links[$_GET['go']]);
}
else{
    header('Location: http://www.website.com/404.htm');
}

?>

Link to comment
Share on other sites

  • 0

Took me less then  a sec...

works with http://domain.com/redirect.php?code

 

Edit: you were quicker :p

<?php
$input = "";
$input = key($_GET);
$u = array();

//Feel free to add urls with codes below
$u[404] = "http://example.com";
$u[666] = "http://neowin.net";
$u[000] = "http://google.com";
$u["youtube"] = "http://yt.be";


foreach($u as $code => $url) {
	if($code === $input) {
		header("Location: $url");
		die();
	}
}
?>

Well I wasn't able to find what I wanted, so I wrote it up.

Here you all go if you need it:

 

<?php

$links = parse_ini_file('urllist.txt');

if(isset($_GET['go']) && array_key_exists($_GET['go'], $links)){

    header('Location: ' . $links[$_GET['go']]);

}

else{

    header('Location: http://www.website.com/404.htm');

}

?>

I like the way you used array_key_exists instead of loop :D
Link to comment
Share on other sites

  • 0

Well I wasn't able to find what I wanted, so I wrote it up.

Here you all go if you need it:

 

<?php

$links = parse_ini_file('urllist.txt');

if(isset($_GET['go']) && array_key_exists($_GET['go'], $links)){

    header('Location: ' . $links[$_GET['go']]);

}

else{

    header('Location: http://www.website.com/404.htm');

}

?>

 

Good job!   

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.