当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

laravel-url-signer

授权协议 MIT License
开发语言 PHP
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 狄鸿禧
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

THIS PACKAGE IS NOT MAINTAINED ANYMORE.SIGNING URLS IS NOW PART OF LARAVEL: https://laravel-news.com/signed-routes

Create secured URLs with a limited lifetime in Laravel

This package can create URLs with a limited lifetime. This is done by adding an expiration date and a signature to the URL.

This is how you can create signed URL that's valid for 30 days:

UrlSigner::sign('https://myapp.com/protected-route', 30);

The output will look like this:

https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx

The URL can be validated with the validate-function.

UrlSigner::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');

The package also provides a middleware to protect routes.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

As you would have guessed the package can be installed via Composer:

composer require spatie/laravel-url-signer

In Laravel 5.5 the service provider and facade will automatically get registered. In older versions of the framework, just add the serviceprovider, and optionally register the facade:

// config/app.php

'providers' => [
    ...
    Spatie\UrlSigner\Laravel\UrlSignerServiceProvider::class,
];

'aliases' => [
    ...
    'UrlSigner' => Spatie\UrlSigner\Laravel\UrlSignerFacade::class,
];

Configuration

The configuration file can optionally be published via:

php artisan vendor:publish --provider="Spatie\UrlSigner\Laravel\UrlSignerServiceProvider"

This is the content of the file:

return [

    /*
    * This string is used the to generate a signature. You should
    * keep this value secret.
    */
    'signatureKey' => env('APP_KEY'),

    /*
     * The default expiration time of a URL in days.
     */
    'default_expiration_time_in_days' => 1,

    /*
     * These strings are used a parameter names in a signed url.
     */
    'parameters' => [
        'expires' => 'expires',
        'signature' => 'signature',
    ],

];

Usage

Signing URLs

URL's can be signed with the sign-method:

UrlSigner::sign('https://myapp.com/protected-route');

By default the lifetime of an URL is one day. This value can be change in the config-file.If you want a custom life time, you can specify the number of days the URL should be valid:

//the generated URL will be valid for 5 days.
UrlSigner::sign('https://myapp.com/protected-route', 5);

For fine grained control, you may also pass a DateTime instance as the second parameter. The urlwill be valid up to that moment. This example uses Carbon for convenience:

//This URL will be valid up until 2 hours from the moment it was generated.
UrlSigner::sign('https://myapp.com/protected-route', Carbon\Carbon::now()->addHours(2) );

Validating URLs

To validate a signed URL, simply call the validate()-method. This return a boolean.

UrlSigner::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');

Protecting routes with middleware

The package also provides a middleware to protect routes:

Route::get('protected-route', ['middleware' => 'signedurl', function () {
    return 'Hello secret world!';
}]);

Your app will abort with a 403 status code if the route is called without a valid signature.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ vendor/bin/phpunit

Usage outside Laravel

If you're working on a non-Laravel project, you can use the framework agnostic version.

Similar libraries

If you need signed url's for CloudFront, consider dreamonkey's package, which is based on this library.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

  • echo '<pre>'; var_dump( $request->url() ); // url echo '</pre>'; echo '<pre>'; var_dump( $request->route( 'email' ) ); //获取路由参数 echo '</pre>';

  • //正则 public function rules() { return [ 'name' => 'required', 'url' => array('regex:/(https?|http?|ftp?):\/\/?/i') ]; } //提示 public function messages() { return

  • <?php namespace App\Http\Controllers; use App\Article; use Carbon\Carbon; use App\Http\Requests\Request; use Illuminate\Support\Facades\DB; class ArticleController extends Controller { public

  • 当前的url     \Request::getRequestUri() 当前route   \Request::route()->getName()

  • 转载:https://learnku.com/laravel/wikis/15962 在Laravel中,有很多种方式获取当前访问 URL: 1. 使用 Request 类: $url = Request::getRequestUri(); 2. 使用 $request 对象: public function show(Request $request) { $url = $requ

  • url 重定向 use Illuminate\Http\RedirectResponse; $response = new RedirectResponse($url);  return $response; 设定cookies use Illuminate\Support\Facades\Response as FacadeResponse;         $content = view('s

  • laravel使用一种简单的方式来访问用户提交的信息。 你可以用统一的方式来访问用户提交的信息,而不用为用户提交信息的方式操心。 引用类:use Illuminate\Support\Facades\Input; 获取一个用户提交的值 代码如下: $name = Input::get('name'); 为用户提交信息指定一个的默认返回值(如果用户未提交) 代码如下: $name = Input::

  •     Route::get(' $path ',' 控制器@方法'); function url($path = null, $parameters = [], $secure = null) $path为路径,$parameters为混合型数据 Route::get(' $path ',' 控制器@方法')->name(' name '); function route($name, $par

  • [Laravel—Route中几乎所有的参数传递](http://www.cnblogs.com/wuoshiwzm/p/6181759.html) Laravel—Url中带参数,各种必选,可选参数,的书写,以及参数正则的匹配 Laravel—Blade模板视图详解 写了如何尝试流程上完整的建立登录页面,看上去细节丰富,但是关键步骤丢失的Larabel使用模板攻略 2.细读了好几篇文章,终于找

  • Route::currentRouteName()   转载于:https://www.cnblogs.com/ryanLee1/p/7246961.html

  • laravel框架如何去掉URL中的index.php 1、将框架根目录下的server.php文件重命名为index.php 2、将框架根目录下的文件夹public下的.htaccess文件复制到框架根目录下,与index.php处于同一目录 3、修改Apache的httpd.conf文件   1、httpd.conf文件所在路径\bin\apache\apache2.4.23\conf\htt

  • 当前的url     \Request::getRequestUri() 当前route   \Request::route()->getName() 转载于:https://www.cnblogs.com/vinzen/p/9677467.html

  • WPCMF 开源内容管理系统  https://gitee.com/wpcmf/wpcmf.git 在一个项目中,您可能需要生成唯一的 URL,这些 URL 执行一些您需要确保用户没有以任何方式更改 URL 的代码。例如,从时事通讯中取消订阅用户,或者为用户创建一个无需密码即可注册的链接,您可能还希望仅为您的电子邮件订阅者提供折扣。 无论您的用例是什么,Laravel 都提供了允许我们使用签名 U

  • 基础URL(常用):{{url('Admin/Member/Delete')}}<br> 路由URL(常用):{{route('Member/Delete')}}<br> 控制器URL: {{action('Admin\MemberController@delete')}}<br>

  • 版权声明:本文为勇哥原创文章,转载请注明出处哦!!!    https://blog.csdn.net/woshihaiyong168/article/details/52993235 laravel使用一种简单的方式来访问用户提交的信息。 你可以用统一的方式来访问用户提交的信息,而不用为用户提交信息的方式操心。 引用类:use Illuminate\Support\Facades\Input;

  • url() 通过url辅助函数(路由)生成: location.href = "{{url('user/index')}}"; 或者:location.href = "{{url::to('user/index')}}";   route() 通过别名(路由)生成,前提是在注册路由的时候要指定别名,例如:Route::get('user/index',['as' => 'user/index1',

  • 关于 拾年之璐 微信公众号:知行校园汇,点击查看,欢迎关注 其他平台(点击蓝字可访问): GitHub  |  Gitee  |  哔哩哔哩  |  语雀  |  简书  |  微信小程序  |  知行达摩院   本文专栏:Laravel  点击查看系列文章 1、框架提供了 url()助手函数 ,方便我们生成各种想要 url 地址;(当然使用 URL也是可以 的) //生成指定的url $user

  • 使用 Request 类: $url = Request::getRequestUri(); 使用 $request 对象: public function show(Request $request) { $url = $request->url(); } 使用 URL 类: $url = URL::current(); 全部的url 使用 Input 类 $url = In

  • 在模板中获取url 有三种方式,url() / action() /route() <a href="{{ url('url') }}">url()</a> <a href=" {{ action('StudentController@urlTest') }}">action()</a> <a href="{{ route('urltest1') }}">route()<

  • 微信小程序: wx.request({ url: ‘https://m.sybmfw.cn/api/ys_user/’ + openid, method:‘put’, data:that.data.formdata, header: { ’content-type’: ‘application/x-www-form-urlencoded’//必须用该类型 }, php laravel return

 相关资料
  • 问题内容: 有没有办法在Laravel 4中获得漂亮的分页URL? 例如,默认情况下: 我想得到的是: 同样,分页应以这种方式呈现,并且添加到分页应以这种方式出现。 问题答案: 这是一个骇人的解决方法。我正在使用Laravel v4.1.23。假设页码是您网址的最后一位。还没有进行深入的测试,因此我对人们可以找到的任何bug感兴趣。我对更好的解决方案更感兴趣:-) 路线: 视图: 模型: 移民:

  • 你好,我正在使用Laravel5进行我的项目。 我有这样的路线: 它对我的分页画廊非常有用。但我看到,当我向url添加额外的参数end of时,它仍然有效。 例子: 通常它不应该工作。但它显示了相同的画廊页面。 我尝试了一些代码,但对我无效: 当尝试这些代码时,仍会打开同一页。 如何阻止或重定向此参数到404页? 谢谢

  • 从我搜索的url中删除public/from并尝试执行以下步骤 > 抄袭。htaccess from public/并将其粘贴到root/ 更改服务器。php来索引。php 我试着补充一下 RewriteRule上的RewriteEngine^(.*)$public/$1[L] 我的 /.htaccess删除网址公共它没有工作。 但是,如果我删除了这一行它的工作,但我所有的Url链接到css它的错

  • 很好的一天! 你好 目前我在laravel工作,我是新来的。我一直在寻找我的问题的解决方案,但我找不到解决方案。我laravel的工作是访问已经没有 /public在网址我修复这个通过. htaccess,但它可以访问也与 /public在网址。请看下面的链接供您参考。 https://utok.ph/ https://utok.ph/public 我的htaccess文件 重写引擎在重写规则 ^

  • 我在/app/Http/Controllers/Hello中创建了控制器。php由php artisan制作:控制器您好 我在/app/Http/routes中添加了以下代码。php 当我运行我的laravel应用程序时http://localhost/laravel/public/ 它在中央显示拉威尔 但是当我使用http://localhost/laravel/public/hello它生成“

  • 我用这个将所有内容都指向/public文件夹。htaccess。 这很好,我可以在没有/public的情况下加载/administration路径,但问题是,我也可以像这样加载/public/administration。