简体   繁体   中英

Auto secure form on Laravel 4.2

I'm using Laravel 4.2 and everything looks fine. But I have a problem with the SSL when I use Form::open() Function. It always using HTTP without SSL even when the site is using SSL.

I saw this question: Laravel: HTTPS in Form::open() But there's 2 problems with that: I need to do it manually for each form. and when I program on my Wamp Server, I have HTTP so it won't work on my localhost.

So my question is, How can I auto secure the form if the site is using SSL?

You can create a route group with the https option, and insert all of your routes inside that group.

Example:

Route::group(array('https'), function(){
    // All routes goes here
});

Then your forms should be https .

Another solution may be just:

URL::forceSchema("https");

You can use Request::secure() to check if the request is over HTTPS and use the return value in the URL helper like this:

Form::open(array('url' => URL::to('/', array(), Request::secure())))

This way you form should automatically use HTTP or HTTPS depending if the current request is using HTTPS or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM