Mar
9

Short URL Script FREE Rapidshare Links for Download

   Posted by: Cyb0rg at 7:50am in General

In this tutorial i am going to teach you how to create your very own tinyurl like script …

First off…the complete script requires a few things:
Linux Web Hosting.
1 MySQL Database.
"public_html" folder allowed to be chmoded to 777.

If any of those 3 things are not possible/not available…then the script will not work on your hosting space.

Right, Short URL Scripts are used to create shorter urls for people to use.
For example:
If I wanted to show off my site: http://www.sub-domain.a-domain.com/directory/myphppage.php but I thought the url was too long for people to ever remember, I would simply place my url into a short url script and it will create a shorter url, for example http://www.gfxclass.com/49. That gfxclass.com link would then redirect to my original long url.

Step One:
I suppose we’re going to want to create the MySQL Database…

Log in to your cPanel. (The following steps may differ depending on what version of cPanel you use, I am writing this based off cPanel 10.8.1).
Now, go to the MySQL Databases section, add a database…probably best to call it something similar to your domain name.
Once you have added that, you have to add a User, shouldn’t be too hard…

Now add the user to the database, with Privileges set to ALL.

Once the user is added, click the phpMyAdmin link at the bottom of the page (may be different for different cPanels).

On the left of phpMyAdmin, there is a drop-down menu…on that select the database you have just created.

On the right (in the main box), a set of tabs should have appeared above the main content, click the SQL tab.
Now in the text box, copy this into it:

CREATE TABLE `url` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`url` text NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM;

Now press the Go button.
That will create a table in the database (url).

Step Two:
Now that we have all the MySQL stuff out the way…we’re going to set up a file that will connect with the database.

Open Notepad (or any other html editor) and copy in this code:

<?
$server = "localhost";
$username = "user";
$password = "pass";
$database = "user_db";
?>

Explanation:
$server = "localhost"; is usually set at localhost but may be different for your server.
$username = "user"; change user to the username that you added to your database.
$password = "pass"; replace pass with the password you set with your user.
$database = "user_db"; replace user_db with the name of that database.

Save that file as "config.php".

Step 3:
Now we’re going to create a page that will list all of the short urls that have been processed by the script, this is mainly for admin use…but you can always link to it if you want.

Save the following as "viewall.php"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>yourdomain.com</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>

<body>
<?
echo "<b>Database Output</b><br /><br />";

include("config.php");
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query="SELECT * FROM url";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$url=mysql_result($result,$i,"url");

echo "<a href="http://www.yourdomain.com/$id">www.yourdomain.com/$id</a> - $url<br />";

$i++;
}
?>
</body>
</html>

Obviously change yourdomain.com with your actual domain…

Step Four:
Before we create the index page, I think it would be a good idea to make it look good using CSS.

Save the following as stylesheet.css:

/* CSS Document */

body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
background-color:#EBEBEB;
color: #000000;
}

div {
padding: 1px;
}

a:link { color: #004E82; text-decoration:none; }
a:visited { color: #004E82; text-decoration:none; }
a:hover { color: #E9592F; text-decoration:underline; }
a:active { color: #004E82; text-decoration:none; }

div.header {
border-left:1px solid #000000;
border-right:1px solid #000000;
border-top:1px solid #000000;
border-bottom:1px solid #000000;
width:40%;
font-size:18px;
}

div.inside {
background-color: #CCCCFF;
color: black;
}

div.main {
border-left:1px solid #000000;
border-right:1px solid #000000;
border-bottom:1px solid #000000;
width:40%;
font-size:11px;
border-top:none;
vertical-align:middle;
padding-bottom:0px;
padding-top: 8px;
}

div.footer {
border-left:1px solid #000000;
border-right:1px solid #000000;
border-bottom:1px solid #000000;
width:40%;
font-size:9px;
border-top:none;
}

Feel free to edit all the hex codes etc.

Step Five:
Now for the index file…

Copy all the code from the text box below and save it as index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>//yourdomain.com :: The URL Shortening Site!</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<center><br></br><br></br>
<div class="header"><div class="inside"><a href="index.php">yourdomain.com</a></div></div>
<div class="main"><br></br><br></br><br></br><?php
include("config.php");
$c = $_POST[’url’];
$go = $_POST[’go’];
if (!$go) {
echo "<form method=’post’ action=”>";
echo "HTTP://<input name=’url’ value=” />";
echo "<input name=’go’ value=’Make Short URL’ type=’submit’ />";
echo "</form>";
}
else if ($c) {
@mysql_connect ($server, $username, $password);
@mysql_select_db ($database);
$query = "SELECT id FROM url ORDER BY id DESC LIMIT 0,1";
$r = mysql_query($query);
while ($row = @mysql_fetch_array($r)) {
$lastid = $row[id];
}
$newid = $lastid + 1;
mysql_query ("INSERT INTO url VALUES (”,’$c’)");
mkdir("$newid");
$file = fopen("$newid/index.php", "w");
$c = "$c";
fwrite($file, "<? header(’location:http://$c’); ?>");
fclose($file);
mysql_close();
echo "Thank you! Your new Short URL is <a href=’http://www.yourdomain.com/$newid’>http://www.yourdomain.com/$newid</a><br /><a href="index.php">Go Back</a><br /> ";
} else {
echo "You did not specify your current URL<br /><a href="index.php">Go Back</a><br /><br />";
}
?><br></br><br></br></div>
<div class="footer"><div class="inside">Short URL Scritp Copyright <a href="http://www.gfxclass.com/">//GFXClass.com</a>


This entry was posted on Sunday, March 9th, 2008 at 7:50 am and is filed under General. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment