Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


URL Shortener

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Web Development
View previous topic :: View next topic  
Author Message
Lyfa
The Lonely Man
Reputation: 11

Joined: 02 Nov 2008
Posts: 744

PostPosted: Mon Aug 02, 2010 2:42 pm    Post subject: URL Shortener Reply with quote

Only needs two files.

index.php:
Code:
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "url";

$con = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $con);

$error = "";
if (isset($_GET['id'])) {
    if(is_numeric($_GET['id'])) {
        $id = $_GET['id'];
        $sql = mysql_query("SELECT * FROM urls WHERE id = '".$id."'") or die(mysql_error());
        $data = mysql_fetch_assoc($sql);
        if($sql) {
            header("location: ".$data['url']."");
        } else {
            $error = '<div class="error">That URL is not in our database</div>';
        }
    } else {
        $error = '<div class="error">That URL is not in our database</div>';
    }
}
if(isset($_POST['url'])) {
    $url = mysql_real_escape_string(stripslashes($_POST['url']));
    if(!filter_var($url, FILTER_VALIDATE_URL)) {
        $error = '<div class="error">That is not a valid URL</div>';
    } else {
        $sql = mysql_query("INSERT INTO urls (url, date) VALUES ('".$url."', '".time()."')") or die(mysql_error());
        if($sql) {
            $grab = mysql_query("SELECT * FROM urls ORDER BY id DESC LIMIT 1") or die(mysql_error());
            $data = mysql_fetch_assoc($grab);
            $error = '<div class="success">Your URL has been entered<br />It is: <a href="http://'.$_SERVER['SERVER_NAME'].'/'.$data['id'].'">http://'.$_SERVER['SERVER_NAME'].'/'.$data['id'].'</a></div>';
        } else {
            $error = '<div class="error">There was an error entering the URL into the database</div>';
        }
    }
}
if(empty($error)) {
    $error = "Please enter a URL in the textbox below";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>F3ar's URL Shortener</title>
        <style type="text/css">
            body {
                background: #999999;
                height: 100%;
            }
   
            #errorbox {
                position: absolute;
                left: 30%;
                top: 5%;
                width: 528px;
                background: lightgrey;
                display: table-cell;
                padding: 10px 15px 10px 15px;
                text-align: center;
                color: grey;
                font-family: arial;
                text-shadow: 0px 1px 0px rgba(255,255,255,0.8);
                border: 2px solid #555;
       
                -webkit-box-shadow: 0px 1px 5px grey;
                -moz-box-shadow: 0px 1px 5px grey;
                box-shadow: 0px 1px 5px grey;
       
                -webkit-border-radius: 10px;
                -moz-border-radius: 10px;
                border-radius: 10px;
            }
   
            .error {
                color: red;
                font-weight: bold;
            }
   
            .success {
                color: green;
                font-weight: bold;
            }
            .success a {
                color: blue;
                font-weight: bold;
            }
           
            #greybox {
                position: absolute;
                left: 31%;
                top: 8%;
                width: 500px;
                background: lightgrey;
                display: table-cell;
                padding: 55px 15px 25px 15px;
                text-align: center;
                color: grey;
                font-family: arial;
                text-shadow: 0px 1px 0px rgba(255,255,255,0.8);
                border: 1px solid #333;
       
                -webkit-box-shadow: 0px 1px 5px grey;
                -moz-box-shadow: 0px 1px 5px grey;
                box-shadow: 0px 1px 5px grey;
       
                -webkit-border-radius: 10px;
                -moz-border-radius: 10px;
                border-radius: 10px;
            }
   
            a {
                color: #666666;
            }
        </style>
    </head>
    <body onload="document.getElementById('url').focus()">
        <div id="greybox">
            <form action="" method="POST">
                <label for="url">URL: </label><input type="text" name="url" id="url" value="http://" /><br />
                <input type="submit" value="Shrink it!" />
            </form>
        </div>
        <div id="errorbox"><?php echo $error; ?></div>
    </body>


.htaccess:
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)$ index.php?id=$1


Create a database and insert this:
Code:
CREATE TABLE IF NOT EXISTS `urls` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `url` varchar(500) NOT NULL,
  `date` varchar(25) NOT NULL,
  `disabled` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

_________________
Back to top
View user's profile Send private message
Cryoma
Member of the Year
Reputation: 195

Joined: 14 Jan 2009
Posts: 1848

PostPosted: Mon Aug 02, 2010 3:09 pm    Post subject: Reply with quote

Right on.
Back to top
View user's profile Send private message
Garavito
Master Cheater
Reputation: 0

Joined: 21 Jun 2009
Posts: 387

PostPosted: Mon Aug 02, 2010 5:14 pm    Post subject: Reply with quote

Looks cool now we just need to buy cool domains like "blah.smokes.cra.ck"
_________________
Back to top
View user's profile Send private message
Maes
Advanced Cheater
Reputation: 10

Joined: 09 Apr 2009
Posts: 53

PostPosted: Tue Aug 03, 2010 5:33 pm    Post subject: Reply with quote

Would you be able to redo this in a way that it makes a subdomain link, instead of like http://example.com/65dfd4, so it would look like http://65dfd4.example.com/
_________________
Account reclaimed by former owner?
Back to top
View user's profile Send private message
Lyfa
The Lonely Man
Reputation: 11

Joined: 02 Nov 2008
Posts: 744

PostPosted: Tue Aug 03, 2010 9:45 pm    Post subject: Reply with quote

Rokurai wrote:
Would you be able to redo this in a way that it makes a subdomain link, instead of like http://example.com/65dfd4, so it would look like http://65dfd4.example.com/
It should work for that already.
_________________
Back to top
View user's profile Send private message
Maes
Advanced Cheater
Reputation: 10

Joined: 09 Apr 2009
Posts: 53

PostPosted: Wed Aug 04, 2010 1:16 pm    Post subject: Reply with quote

F3ar wrote:
Rokurai wrote:
Would you be able to redo this in a way that it makes a subdomain link, instead of like http://example.com/65dfd4, so it would look like http://65dfd4.example.com/
It should work for that already.

It only gives me "http://localhost/5gd43"

_________________
Account reclaimed by former owner?
Back to top
View user's profile Send private message
Lyfa
The Lonely Man
Reputation: 11

Joined: 02 Nov 2008
Posts: 744

PostPosted: Wed Aug 04, 2010 5:56 pm    Post subject: Reply with quote

Rokurai wrote:
F3ar wrote:
Rokurai wrote:
Would you be able to redo this in a way that it makes a subdomain link, instead of like http://example.com/65dfd4, so it would look like http://65dfd4.example.com/
It should work for that already.

It only gives me "http://localhost/5gd43"
It takes the server name, so if it's on localhost it'll give localhost, if it's on google.com it'll say google.com
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Web Development All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites