Heey m8'ts
I was bored so I made this:
inc.php
PHP Code:
<?
$dbhost = ""; //Your database host: localhost
$dbuser = ""; //Your database user
$dbpass = ""; //Your database password
$db = ""; //Your database
$url = ""; //Your webpage url
?>
db.php
PHP Code:
<?
mysql_connect ('$dbhost', '$dbuser', '$dbpass');
mysql_select_db('$db');
?>
index.php
PHP Code:
<?
include('inc.php');
if($id == ""){
?>
<form action='?id=post' method='post'>
Link: <input name='link' type='text'><input type='submit' value='Make short link'>
</form>
<?
}elseif($id == "post"){
if($_POST[link] == ""){
echo "You have to write a link. <br><a href='?id='>Back</a>";
}else{
include('db.php');
$secink = str_replace("http://", "", $_POST[link]);
$dotiwithlink = "http://$secink";
$random = substr(strtoupper(md5(uniqid("w"))), 0, 5);
$create = "INSERT INTO links (link, rand) VALUES('$dotiwithlink', '$random')";
mysql_query("$create");
echo "New link <input type='text' size='100' value='$url/?id=show&what=$random'>";
}}elseif($id = "show"){
include('db.php');
$result = mysql_query("SELECT * FROM links WHERE rand = '$what'");
$row = mysql_fetch_array($result);
?>
<script type="text/javascript">
<!--
window.location = "<?echo $row[link];?>"
//-->
</script>
<?
}
?>
<!-- Copyright to me :D -->
<center>Scriptet by Helstedxd</center>
The SQL
Code:
CREATE TABLE `links` (
`id` int(11) NOT NULL auto_increment,
`link` text NOT NULL,
`rand` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 AUTO_INCREMENT=1 ;