I need to encrypt routes in this URL? Because I do not want user to access URL by changing the item id. For example, user can change /items/1234 to /item/5678. Although item 1234 and 5678 belong to the same user, I still want to restrict the behavior. What I am trying to do is encrypting the routes but I am not sure whether this is a proper way or not. Any suggestions?
Under Website security, click Traffic encryption (HTTPS/SSL). Choose when you want to redirect visitors to the secure URL. All http page requests will be redirected to the encrypted https page.
PHP | urlencode() Function. The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.
Laravel's encrypter uses OpenSSL to provide AES-256 and AES-128 encryption.
There are multiple ways to hide/mask the ids in the URLs. The first way is by using UUIDs. UUIDs are Universally Unique Identifiers that can be used instead of the default incremental ids. Laravel comes with support for UUIDs.
You can encrypt your url parameter and decrypt it in your controller. You can try this:
In your view: Suppose your parameter is id or more parameter you can encrypt.
<?php
$parameter =[
'id' =>1,
];
$parameter= Crypt::encrypt($parameter);
?>
<a href="{{url('/url/',$parameter)}}" target="_blank">a link</a>
Your route will be:
Route::get('/url/{parameter}', 'YourController@methodName');
In your controller, You can decrypt your parameter:
public function methodName($id){
$data = Crypt::decrypt($id);
}
You must be yous Crypt namespace in your top of controller
use Illuminate\Support\Facades\Crypt;
Note: You can encrypt url parameter with Crypt::encrypt($parameter)
and decrypt with Crypt::decrypt($parameter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With