Download .zip |
Info | View files (6) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2012-11-05 (7 years ago) | Not yet rated by the users | Total: 376 | All time: 6,633 This week: 391 |
Version | License | PHP version | Categories | |||
url-shortener 1.0.0 | GNU General Publi... | 5.0 | HTTP, PHP 5, Databases |
Description | Author | |
This class can create and expand short URLs stored in a MySQL database. |
|
----------------------------------------- INSTALLATION ----------------------------------------- - First, create a new MYSQL database. (e.g. 'linkdb') - Second, create database table using the following SQL statement: CREATE TABLE shortLinks ( id int(11) UNSIGNED NOT NULL auto_increment, ulid varchar(15) NOT NULL default '', longLink varchar(255) NOT NULL default '', PRIMARY KEY(id), UNIQUE(ulid), KEY(longLink) ) TYPE=MyISAM COMMENT='Link Table' CHARSET=utf8 COLLATE=utf8_bin; - Third, open UrlShortener.php class file and enter your details to following private properties. private $dbHost = 'localhost'; private $dbUser = 'db_user'; private $dbPassword = 'db_password'; private $dbName = 'linkdb'; private $dbTable = 'shortLinks'; private $baseUrl = 'http://localhost'; //shouldn't end with / ----------------------------------------- CLASS USAGE ----------------------------------------- 1) To get a long link from the database, you need to specify link_id to getLongUrl() function. Example: $link_id = 'z'; $urlShortener = new UrlShortener(); $long_url = $urlShortener->getLongUrl($link_id); 2) To create short link, you need to specify long_link to getShortUrl() function. Example: $long_link = 'http://www.site.com'; $urlShortener = new UrlShortener(); $short_link = $urlShortener->getShortUrl($long_link); 3) To get only the link_id, you need to call getUrlId() function with long_link parameter. Example: $long_link = 'http://www.site.com'; $urlShortener = new UrlShortener(); $url_id = $urlShortener->getUrlId($long_link); ----------------------------------------- SAMPLE SCRIPT ----------------------------------------- Sample script contains following files: index.php link.php class/UrlShortener.php .htaccess |
Files |
File | Role | Description | ||
---|---|---|---|---|
class (1 file) | ||||
DatabaseTableStructure.txt | Data | database table structure | ||
readme.txt | Doc. | readme | ||
index.php | Example | sample_script - index.php | ||
link.php | Example | sample_script - link.php | ||
.htaccess | Data | sample_script - .htaccess |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.