hirossyi73/url-shorter
Composer 安装命令:
composer create-project hirossyi73/url-shorter
包简介
Encode and decode url shorter.
README 文档
README
This is a library that generates and restores shortened URLs.
Requirement
- PHP >= 8.0.0
- Laravel >= 9.0.0
Functions
- Generate shortened URL
- Restore shortened URL
- Generate short URL from screen(Switchable ON/OFF as an option)
- Generate short URL with API(Switchable ON/OFF as an option)
- Restore short URL with API(Switchable ON/OFF as an option)
- Function that requires password authentication when shortening with screen/API(Switchable ON/OFF as an option)
- Short URL preview function(Switchable ON/OFF as an option)
- Screen/API endpoint change function
- Change the number of random characters in shortened URL
- Change the character type used in the shortened URL
Quick Start
-
Start the console and move to the folder you want to install.
-
Install laravel.
composer create-project "laravel/laravel" .
- Install Url Shorter.
composer require hirossyi73/url-shorter
- Open ".env" file, input database info.
DB_CONNECTION=mysql
DB_HOST=(Host Name)
DB_PORT=(Port Name)
DB_DATABASE=(Database Name)
DB_USERNAME=(User Name)
DB_PASSWORD=(Password)
# To enable the shortened URL function from the screen
URL_SHORTER_ENABLED_WEB_MAKE=true
- Enter the following command.
php artisan vendor:publish --provider="Hirossyi73\UrlShorter\UrlShorterServiceProvider"
php artisan migrate
- Start the server.
php artisan serve
Try
-
By accessing the following URL, it will transition to the shortened URL generation screen.
http(s)://(URL)/make -
Enter the URL and click the "Convert" button.
- You can redirect to the original URL by pasting the generated URL in the browser.
Password Authentication
Password authentication can be set on the shortened URL generation screen.
- Open the ".env" file and enter the following information.
URL_SHORTER_AUTH_USE=true
URL_SHORTER_AUTH_PASSWORD=(Password)
- Now, when you access the shortened URL generation screen, you will be prompted for password authentication.
Preview
-
When you enter the shortened URL in the browser, you can display the preview screen without directly redirecting.
-
Open the ".env" file and enter the following information.
URL_SHORTER_USE_PREVIEW=true
- If you enter the shortened URL in your browser, you will be prompted for a preview.
API
You can use the API.
- Open the ".env" file and enter the following information.
URL_SHORTER_ENABLED_API=true #When using original URL recovery from shortened URL
URL_SHORTER_ENABLED_API_MAKE=true #When using shortened URL generation
- You can now use the shortened URL API.
Generate short URL
http(s)://(URL)/api/make POST
Content-Type : application/json
POST VALUE:
{
"url": "(URL to shorten)"
}
RETURN VALUE:
{
"url": "(URL to shorten)",
"key": "(Key)",
"updated_at": "(Updated Datetime)",
"created_at": "(Created Datetime)",
"generate_url": "(Generate URL)"
}
Restore from shortened URL
http(s)://(URL)/api/g POST
Content-Type : application/json
POST VALUE:
{
"generate_url": "(Shortened URL)"
}
RETURN VALUE:
{
"url": "(URL to shorten)",
"key": "(Key)",
"updated_at": "(Updated Datetime)",
"created_at": "(Created Datetime)",
"generate_url": "(Generate URL)"
}
Setting Value
Add to ".env" file.
URL_SHORTER_USE_PREVIEW
When using the preview function, set true(Default : false)
URL_SHORTER_AUTH_USE
When password authentication is performed with the shortened URL generation function, set true(Default : false)
URL_SHORTER_AUTH_PASSWORD
Password string for password authentication
URL_SHORTER_GENERATE_WORDS
Character string used when generating a shortened URL
URL_SHORTER_GENERATE_LENGTH
Number of characters when generating a shortened URL
URL_SHORTER_GENERATE_CHECK_ALREADY_EXISTS
When true, check existence after creating short keys(Default : true)
URL_SHORTER_ENABLED_WEB
If true, use redirect page when accessing shortened URL(Default : true)
URL_SHORTER_ENABLED_WEB_MAKE
When true, use shortened URL generation page(Default : false)
URL_SHORTER_ENABLED_API
When true, use API to get original URL from shortened URL(Default : false)
URL_SHORTER_ENABLED_API_MAKE
When true, use shortened URL generation API(Default : false)
hirossyi73/url-shorter 适用场景与选型建议
hirossyi73/url-shorter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 224 次下载、GitHub Stars 达 11, 最近一次更新时间为 2020 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hirossyi73/url-shorter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hirossyi73/url-shorter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 224
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-10


