connect_error) { header("Location: dberror.html"); exit(); } $sError=''; $sRedir=$_GET['longurl']; if ( ereg("^[0-9A-Fa-f]+$",$sRedir ) ) { $sStmt=$oDB->prepare("select realurl from longurl where id=?"); $sStmt->bind_param("s",$sRedir); $sStmt->execute(); $sStmt->bind_result($sNewURL); $sStmt->fetch(); print "$sNewURL $sRedir

"; if ( $sNewURL!='' ) { header("Location: $sNewURL"); exit(); } else { $sError="URL Not Found"; } } else { $sRedir=''; } if ( $_POST['wtf']=='wtf' ) { $sURL=$_POST['url']; if ( ! ereg("^(http[s]?)|(ftp)://",$sURL) ) { $sURL='http://'.$sURL; } if (ereg("^((http[s]?)|(ftp))://([^/]+)/?(.*)$",$sURL,$aMatch) ) { $sMethod=$aMatch[1]; $sHost=$aMatch[4]; $sRest=$aMatch[5]; $sIP=gethostbyname($sHost); if ( $sIP==$sHost ) { $sIP=long2ip(ip2long($sHost)); if ( $sIP!=$sHost ) { $sError="Bad Host Name"; } } $sURL=$sMethod."://".$sHost."/".$sRest; } else { $sError="Bad URL"; } } ?> URL Lengthening Service

URL Lengthening Service

Because I am sick of all these URL shortening services, I wrote this URL lengthening service. Here is how it works: Enter your long and uggly URL below. Click submit, and in return get an even longer and ugglier URL back.

Right now, there is no preview option. Preview takes the excitement out of clicking random links.

All URLs created by the service (including the http:// part) are exactly 140 characters long.

$sError"; if ( $sError=='' ) { $sLongURL=$sBaseURL; $sLongURLID=sha1($sURL).md5($sURL).sha1($_SERVER['REMOTE_ADDR']); $sLongURLID=substr($sLongURLID,0,140-strlen($sLongURL)); print "

Your Long URL:

$sLongURL$sLongURLID

"; $sStmt=$oDB->prepare("select count(*) from longurl where id=?"); $sStmt->bind_param("s",$sLongURLID); $sStmt->execute(); $count=0; $sStmt->bind_result($count); $sStmt->fetch(); $sStmt->close(); if ($count==0 ) { if ( $sStmt=$oDB->prepare("insert into longurl (id, realurl, created, createby) values (?,?,now(),?)") ) { $sStmt->bind_param("sss",$sLongURLID,$sURL,$_SERVER['REMOTE_ADDR']); $sStmt->execute(); } } } } ?>
Your Short URL

BY AGREENING TO USE THIS SERVICE, YOU SURRENDER ALL CURRENT, PAST AND FUTURE PRIVACY RIGHTS.

reddit


Learn how to code PHP securely . Now without having to leave the comfort of you house! DEV545 Secure Coding in PHP: Developing Defensible Applications.

ToDo: