The way you propose is 1. harder to validate. 2. Someone could stick a cross site scripting attack in the url like redirect.php?<script>alert('xss');</script> . Your also missing an extra part of the query. You will need some thing for $_GET so maby use ?url=
so redirect.php?url=http://example.com
Then could get the url by doing
PHP Code:
$toRedirect = $_GET['url'];
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"3;URL={$toRedirect}\">";
But also you would have to validate it.. which is the hard part and I cannot think of anything at the moment quickly that would validate that.
Better to use an Integer for the $_GET. like redirect.php?id=1 . Then in your mysql query you can get the url by the example code below, Assuming in your mysql database table there is a field called "url" that has url like "http://example.com" and also an auto_incrementing field called "id".
Btw this code could have syntax error. I didn't run it. I just wrote it off the top of my head while posting this.
PHP Code:
<?php
$id = false;
// If ?id= is set is only a integer.
if(!empty($_GET['id']) && is_numeric($_GET['id'])) {
$id = $_GET['id'];
}
$sql = array();
$link = mysql_connect('localhost', 'database_user', 'database_password') or die('Could not connect: ' . mysql_error());
$db_selected = mysql_select_db('database_name',$link) or die(mysql_error());
sql = mysql_query('SELECT * FROM url_table WHERE id={$id}') or die("oops");
$toRedirect = mysql_fetch_assoc($sql);
// If id does not exist
if(!toRedirect) {
header('HTTP/1.0 404 Not Found');
exit('Not Found');
}
echo "<html><head><title>Redirection...</title>"
. "<meta http-equiv=\"refresh\" content=\"5;url={$toRedirect['url']}\"/>"
. "</head><body><h1>You being redirected to"
. "<a href=\"{$toRedirect['url']}\">{$toRedirect['url']}</a>"
. "</body></html>";
Of course there is many other things you could do like count hits to the link.
Bookmarks