2016-12-28 107 views
3

我想在表單提交時加密參數。我使用的是laravel 5.2版本,當表單提交時,我使用get method提交表單。但是當提交表單的時候在URL中顯示所有參數。所以我必須加密所有這些參數。例如如何使用GET方法使用Laravel形式在URL中以加密格式傳遞GET參數?

http://localhost:8000/get/experiences?category_id=18 

http://localhost:8000/get/experiences/AQBBShSqt4zxsClTymwBhjIUP1kG7HEoqhoKMfAAlsMk2ZUOxStqGLAFFg0mM1nRKMEVVbB97xCvfRJTP0ZH3k1Am 

我怎樣才能做到這一點?

+0

爲什麼不使用POST方法? –

+0

我不能使用post方法,因爲在url上輸入show error Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201: –

+0

請看看http://jenssegers.com/64/easy-id-obfuscation-with -laravel-5 –

回答

1

您需要定義路線:

Route::post('/get/experiences/{category_id}', '[email protected]'); 

之後,你可以使窗體:

<form action="{{ url('/get/experiences/'.encrypt($category_id)) }}" method="post"> 
<!-- all your form data --> 
<input type="submit" value="Post"> 
</form> 

這將發出一個POST請求路線,/get/experiences/{category_id}它將encrypt$category_id使用encrypt方法。

希望這個作品!

+0

我有超過十個參數,所以如何添加? –

+0

我建議發佈所有這些參數,而不是網址。 @dhanashri –

0

您可以使用post方法。將Route::post('/get/experiences/{category_id}', '[email protected]');添加到您的航線,並且不要忘記在您的表單標籤中添加{!! csrf_field() !!}代碼。

參數將不會顯示在URL中,因此您不必進行加密。當然,如果你不想使用get方法來加密。

相關問題