Forum Moderators: coopster
For example, I want to be able to put the following link on my site
[example.com...]
Then when someone clicks the link, the redirect.php file check's a db and recognizes test.com in an entry and see's it's suppose to redirect it to
[test.com...]
and does. Does anyone know of a pre-made script to allow this or know how to do such a thing if one doesn't exist? Thanks
mysql> describe jump;
+-------+-------------+------+-----+---------+-------+
¦ Field ¦ Type ¦ Null ¦ Key ¦ Default ¦ Extra ¦
+-------+-------------+------+-----+---------+-------+
¦ tag ¦ varchar(40) ¦ ¦ PRI ¦ ¦ ¦
¦ url ¦ text ¦ ¦ ¦ ¦ ¦
¦ count ¦ int(11) ¦ ¦ ¦ 0 ¦ ¦
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)<? $jump = getenv("QUERY_STRING");
$link = mysql_connect(BLAHBLAHBLAH);
mysql_select_db("MYDB");
$query = sprintf("SELECT url FROM jump WHERE tag = '%s'", mysql_real_escape_string($jump));
$result = mysql_query($query);
$row = mysql_fetch_row($result);
if (mysql_num_rows($result) == 0) {?>
<p>I'm sorry, I can't find that link. Please try a search.</p>
Search: <form action="/cgi-bin/htsearch" method="get">
<input name="words">
</form>
<?
exit;
}
$query = sprintf("UPDATE jump SET count = count + 1 WHERE tag = '%s'", mysql_real_escape_string($jump));
mysql_query($query);
mysql_close($link);
header("Location: $row[0]"); exit;?>
I don't do full urls in the query string, just a short tag. If you want to do anything bigger, change the "tag" column to a varchar(255) or a text field.