定制 anaskhansays/urlshortner 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

anaskhansays/urlshortner

Composer 安装命令:

composer require anaskhansays/urlshortner

包简介

create short URL with your own domain name

README 文档

README

Custom URL shortner, create short URL with your own domain name. This script creates a clean, short, and tiny link that can be shared easily via email or social media. The database is used to store the information about long and short URL. Also, you can track the number of hits the short URL gets by the visitors.

URL Shortener Library (class.URLShortener.php) The URL Shortener class allow to programmatically create short URL using PHP and MySQL. This class uses PDO Extension to work with the MySQL database, so, PDO object instance is required on initialization of URLShortener class.

Static Variables:

  • $characters – Allowed characters for the short code. (Characters group is separated by |)
  • $tbl_name – Database table name to store the URL and short code info.
  • $ifURLExists – Set to TRUE, to check whether the long URL exists.
  • $codeLength – The length of the short code characters.

Functions:

  • __construct() – Set PDO object reference and timestamp.
  • urlToShortCode() – Validate URL and create short code.
  • validateUrlFormat() – Validate the format of the URL.
  • verifyUrlExists() – Verify the URL whether it exist or not using cURL in PHP.
  • urlExistsInDB() – Check whether the long URL is exist in the database. If exist, return the shot code, otherwise, return FALSE.
  • createShortCode() – Create short code for the long URL and insert the long URL & short code in the database.
  • generateRandomString() – Generate random string (short code) with the specified characters in the $chars variable.
  • insertUrlInDB() – Insert URL info in the database using PDO Extension and MySQL and return the row ID.
  • shortCodeToUrl() – Convert the short code to long URL and insert the hits count in the database.
  • validateShortCode() – Validate the short code based on the allowed characters.
  • getUrlFromDB() – Fetch the long URL from the database based on the short code.
  • incrementCounter() – Increment the URL visits counter in the database for a particular record.

URL Rewrite with HTACCESS If you want to make the URL user-friendly, use HTACCESS with RewriteRule. With mod_rewrite, you can make the URL length shorter and easy to share.

Create a .htaccess file and add the following code.

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9]+)/?$ redirect.php?c=$1 [L] The above HTACCESS RewriteRule will send the request to redirect.php file. So, the redirect.php file name doesn’t need to mention in the short URL.

The short URL without using HTACCESS looks something like this – https://example.com/redirect.php?c=gzYN7BK The short URL with using HTACCESS looks something like this – https://example.com/gzYN7BK

anaskhansays/urlshortner 适用场景与选型建议

anaskhansays/urlshortner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 anaskhansays/urlshortner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 anaskhansays/urlshortner 我们能提供哪些服务?
定制开发 / 二次开发

基于 anaskhansays/urlshortner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-08-13