Code:
index.php
--------
<?
session_start();
// MySQL Configuration
$mysql['server'] = "localhost"; // MySQL Server
$mysql['user'] = ""; // MySQL Username
$mysql['pass'] = ""; // MySQL Password
$mysql['db'] = ""; // Database
$link_to_shortcut = "http://www.yoursite.com/shortcut/"; // Full URL to shortcut folder - END WITH TRAILING SLASH
?>
<form method="POST" action="shortener.php">
<table>
<tr><td>URL:</td><td><input type="text" name="url" value="http://"></td></tr>
<tr><td valign="top">Verify:</td><td><img src="captcha.php"><br/><input type="text" name="captcha"></td></tr>
<tr><td colspan=2><input type="submit" name="submit" value="Shorten URL"></td></tr>
</table>
</form><br/>
<?
if (isset($_POST['submit'])) {
if (!empty($_POST['captcha']) && strstr(strtolower($_SESSION[captchastr]),strtolower($_POST['captcha'])) && $_POST['url'] != "") {
$time = time();
mysql_connect($mysql['server'],$mysql['user'],$mysql['pass']) or die("Could not connect to MySQL - check configuration in this page");
mysql_select_db($mysql['db']) or die("Could not select MySQL database - check configuration in this page");
if (mysql_query("INSERT INTO `shortcuts` VALUES('".$time."','".addslashes($_POST['url'])."')")) {
echo 'Your URL shortcut: <input type="text" value="'.$link_to_shortcut.$time.'.html">';
}
else
{
echo "Could not create shortcut - internal error.";
}
}
else
{
echo "Invalid image verification!<br/>";
}
}
?>
-------
captcha.php
-----------
<?php
session_start();
$strlength = rand(4,7);
function createRandomString() {
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$captchastr = strtoupper(createRandomString());
$randcolR = rand(100,230);
$randcolG = rand(100,230);
$randcolB = rand(100,230);
//initialize image $captcha is handle dimensions 200,50
$captcha = imageCreate(200,50);
$backcolor = imageColorAllocate($captcha, $randcolR, $randcolG, $randcolB);
$txtcolor = imageColorAllocate($captcha, ($randcolR - 40), ($randcolG - 40), ($randcolB - 40));
for($i=1;$i<=$strlength;$i++)
{
$clockorcounter = rand(1,2);
if ($clockorcounter == 1)
{
$rotangle = rand(0,45);
}
if ($clockorcounter == 2)
{
$rotangle = rand(315,360);
}
//$i*25 spaces the characters 25 pixels apart
imagettftext($captcha,rand(14,20),$rotangle,($i*25),30,$txtcolor,"/arial.ttf",substr($captchastr,($i-1),1));
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$txtcolor);
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$backcolor);
}
//Send the headers (at last possible time)
header('Content-type: image/png');
//Output the image as a PNG
imagePNG($captcha);
//Delete the image from memory
imageDestroy($captcha);
$_SESSION[captchastr] = $captchastr;
?>
-----
/shortcut/index.php
----
<?
// MySQL Configuration
$mysql['server'] = "localhost"; // MySQL Server
$mysql['user'] = ""; // MySQL Username
$mysql['pass'] = ""; // MySQL Password
$mysql['db'] = ""; // Database
$ad = "YOUR SITE HERE"; // Advertisement string
mysql_connect($mysql['server'],$mysql['user'],$mysql['pass']) or die("Could not connect to MySQL - check configuration in this page");
mysql_select_db($mysql['db']) or die("Could not select MySQL database - check configuration in this page");
if (isset($_GET['modrw'])) {
$query = mysql_query("SELECT * FROM `shortcuts` WHERE `id` = '".addslashes($_GET['modrw'])."' LIMIT 1");
if (mysql_affected_rows() > 0) {
$row = mysql_fetch_assoc($query);
}
else
{
echo "Invalid Shortcut ID";
exit;
}
}
else
{
exit;
}
?>
<html>
<head>
<title><? echo $ad; ?> - Shortcut - <? echo $row['url']; ?></title>
</head>
<frameset rows="55,*" framespacing="0" border="0" frameborder="0">
<frame name="topper" scrolling="no" noresize src="topframe.php">
<frame name="bottom" src="<? echo $row['url']; ?>" scrolling="auto">
<noframes>
<body>
<p>Please visit <? echo $row['url']; ?></p>
</body>
</noframes>
</frameset>
</html>
-----
/shortcut/.htaccess
RewriteEngine on
RewriteRule ^(.*)\.html$ index.php?modrw=$1 [L]
=======
/shortcut/topframe.php
This is the top frame to the URL shortner. Here you can put a logo for your site, or
whatever your heart might desire.
=========================
mysql table
----------
CREATE TABLE `shortcuts` (
`id` text NOT NULL,
`url` text NOT NULL
);
If you look at the code above
Bookmarks