URL Shortner with DMR
This has been chilling in the Exec VIP section for a while, but I figured it's time to move to Jr VIP.This also ties in with "Baby got back"
Well after editing for a while I came up with this rough copy:
I haven't added anything pretty like a nice installer or even any userinterface features. So that means everything that you want to add needsto be added via mysql or the config file.
Here is a list of what the script does:
- When the user visits the short url, the first page will document his IP address and also the keywords he is using.
- The first page will then meta refresh to the second page.
- The second page now takes the data stored in the temporary tablebased on the users IP, and finds the target url to send them to.
- It will also count a click to the # of clicks
- From here it will check to see if the ref is blank. If it is, then itwill redirect to the specified location in your admin panel or 'target'location in your row for that keyword via meta refresh.
- If the ref is not blank, then it will look for the 'alttarget'location in your row for that keyword. It will now redirect them tothis location via meta refresh.
- If the 'alttarget' database is blank, then it will redirect to the'$dmrfail' location specified in the "configuration.php" file via metarefresh.
- If the user tries to go straight to the 'forward2.php' file, thenthey will be redirected to the '$dmrfail' location via meta refresh.
Here is the original URL Shortner download:
Code:
http://get-shorty.com/beta?force=download]http://get-shorty.com/beta?force=download
For those wanting to install the script on the top level of their domain, check this out:
Code:
http://get-shorty.com/forum/viewtopic.php?id=21]http://get-shorty.com/forum/viewtopic.php?id=21
Now follow their instructions to install. After installed, follow the directions below:
#1 - In the "configuration.php" find the following line:
PHP Code:
Code:
$user_table = 'shorty_users';
Add the following lines after the line above:
PHP Code:
Code:
$url_table = 'temporary_urls';
$ipAddress = $_SERVER['REMOTE_ADDR'];
$referer = $_SERVER['HTTP_REFERER'];
$redirect = 'DOMAIN/SHORTY_FOLDER/forward2.php';
$dmrfail = 'http://google.com';
Change the value "DOMAIN" to match your domain and "SHORTY_FOLDER" tomatch the install folder of shorty if it's not installed on base. Alsochange where you would like to redirect if your script fails. (Don'tredirect to your landing page off of the fail!).
#2 - Now open up "forward.php" and replace all of the code with the following:
PHP Code:
Code:
<?php
require("functions.php");
require("configuration.php");
connect();
$keys = explode("/", $_SERVER['REQUEST_URI']);
$query_insert = "INSERT INTO `".$url_table."` (`IP`, `key1`, `key2`,`key3`, `key4`, `key5`) VALUES ('".$_SERVER['REMOTE_ADDR']."','".$keys['2']."', '".$keys['3']."', '".$keys['4']."', '".$keys['5']."','".$keys['6']."')";
mysql_query($query_insert);
echo "<meta http-equiv=\"refresh\"content=\"0;url=http://".$redirect."\">";
?>
#3- Now create a new file called "forward2.php", this is going to be thesecond page of our DMR. Put the following code into the page:
Option 1: Using Meta Refresh Redirect for Fail <--- Opera will not redirect if script fails
PHP Code:
Code:
<?php
require("functions.php");
require("configuration.php");
connect();
$result = mysql_query("SELECT IP,key1,key2,key3,key4,key5 FROM $url_table WHERE IP='$ipAddress'");
$row = mysql_fetch_row($result);
$result2 = mysql_query("SELECT target,clicks,id,alttarget FROM$main_table WHERE key1='$row' AND key2='$row' AND key3='$row'AND key4='$row' AND key5='$row'");
$row2 = mysql_fetch_row($result2);
$updateclicks = $row2+1;
mysql_query("UPDATE `".$main_table."` SET `clicks`='".$updateclicks."' WHERE `id`='".$row2['2']."'");
if($referer == "")
{
echo "<meta http-equiv=\"refresh\"content=\"0;url=".$row2."\">";
mysql_query("DELETE FROM $url_table WHERE IP='$ipAddress'");
}
else
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=".$row2."\">";
mysql_query("DELETE FROM $url_table WHERE IP='$ipAddress'");
}
if($row2 == "")
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=".$dmrfail."\">";
mysql_query("DELETE FROM $url_table WHERE IP='$ipAddress'");
}
?>
Option 2: Using JavaScript Redirect for Fail <--- Opera will redirect if script fails
PHP Code:
Code:
<?php
require("functions.php");
require("configuration.php");
connect();
$result = mysql_query("SELECT IP,key1,key2,key3,key4,key5 FROM $url_table WHERE IP='$ipAddress'");
$row = mysql_fetch_row($result);
$result2 = mysql_query("SELECT target,clicks,id,alttarget FROM$main_table WHERE key1='$row' AND key2='$row' AND key3='$row'AND key4='$row' AND key5='$row'");
$row2 = mysql_fetch_row($result2);
$updateclicks = $row2+1;
mysql_query("UPDATE `".$main_table."` SET `clicks`='".$updateclicks."' WHERE `id`='".$row2['2']."'");
if($referer == "")
{
echo "<meta http-equiv=\"refresh\"content=\"0;url=".$row2."\">";
mysql_query("DELETE FROM $url_table WHERE IP='$ipAddress'");
}
else
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=".$row2."\">";
mysql_query("DELETE FROM $url_table WHERE IP='$ipAddress'");
}
if($row2 == "")
{
echo '<HEAD>
<SCRIPT language="JavaScript">
window.location="' . $dmrfail . '";
</SCRIPT>
</HEAD>';
mysql_query("DELETE FROM $url_table WHERE IP='$ipAddress'");
}
?>
#4 - Now load up your MYSQL, and follow the instructions below:
(Don't input quotes)
- Load the database that Shorty is installed into, as we need to create a new table
- Now where it says "Create new table on database ..." put in 'temporary_urls' as the name, and '6' for the number of fields
- Now name the Fields the following: 'IP', 'key1', 'key2', 'key3', 'key4', 'key5'
- For the "Type", make them all "TEXT"
- Now hit save
#5 - While in the database, go to the following table "shorty_shorties" and make sure you are in the "structure" view.
- Now where it says "Add ... field(s)", go across to where you see the drop down box. Now select "target" and then click "go"
- In the "Field" category put in 'alttarget', and for the "Type" select "TEXT".
- Hit save
#6 - Your now done setting it up!
Go test it out now by adding some short urls...
^ One last step. For each shorturl that is created, you will need to go to the database and edit the "alttarget" for each row (each keyword) in the "shorty_shorties" table.
Make sure to include the 'http://' at the start of each url.
(Foran easy way to manage mass keywords, export your database to a .csvformat and edit via excel, then import/upload it back into mysql).
If anyone has any questions, feel free to ask.
Demo Added, below are test links. Try them out and see where they redirect in different browsers:
Free web host links will redirect, but slowly
HTML Code:
http://urlshortnerdmr.x10hosting.com/shorty_beta/mmd/rocks/]http://urlshortnerdmr.x10hosting.com/sho...mmd/rocks/
^ Redirects to MMD if ref is blank. Redirects to fmylife if ref isn't blank
HTML Code:
http://urlshortnerdmr.x10hosting.com/shorty_beta/google/testing/googl2/sup/]http://urlshortnerdmr.x10hosting.com/sho...oogl2/sup/
^ Redirects to Google if ref is blank. Redirects to Yahoo if ref isn't blank
HTML Code:
http://urlshortnerdmr.x10hosting.com/shorty_beta/testing/]http://urlshortnerdmr.x10hosting.com/sho...a/testing/
^ Redirects to Bing if ref is blank. Redirects to Yahoo if ref isn't blank
HTML Code:
http://urlshortnerdmr.x10hosting.com/shorty_beta/forward2.php]http://urlshortnerdmr.x10hosting.com/sho...rward2.php
^ Redirects to Ask.com as ref failed to be logged <--- This is using JavaScript Redirect
页:
[1]