Forum Moderators: coopster

Message Too Old, No Replies

Link redirector based on variables

need to know how to do it.....

         

ajs83

6:31 am on Feb 21, 2005 (gmt 0)

10+ Year Member



I'm looking for a script that will take a url and based on pre-defined parameters redirect to a customized url

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

dreamcatcher

8:05 am on Feb 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check out the link tracking scripts at Hotscripts.com.

:)

ajs83

8:34 am on Feb 21, 2005 (gmt 0)

10+ Year Member



I looked and, unless im missing something, they didn't have anything like that.

SeanW

1:58 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



Here's what I use:

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.

ajs83

7:50 pm on Feb 22, 2005 (gmt 0)

10+ Year Member



is that for searches or redirection?

SeanW

8:33 pm on Feb 22, 2005 (gmt 0)

10+ Year Member



This is for redirection, so I can provide smaller urls (ie for newsletters) and track the response.

The search stuff is in there to send the user to a search form if the tag is invalid. Much nicer than returning an error or a blank page.

Sean