Trying to obscure the URL variable is not the correct approach. Instead you need to clean the variable then do a specific permission check.
For variable cleaning you should use required_param() or optional_param() with the correct PARAM_* type. If it is an ID use PARAM_INT. It is recommended you do this near the top of the page and store a variable for using later.
After that you need to confirm that the user viewing the page is allowed to see that record. Typically this is done via a capability check (require_capability()) or a custom piece of code. For example if users are only allowed to see widgets they created, you might have a userid in the widget table. Then you could do:
$widgetownerid = $DB->get_field('widget', 'userid', array('id' => $idfromurl));
if ($USER->id != $widgetownerid) {
// throw an error to prevent access
}
That way, the user can change the URL to anything they want but won't be able to access content that is not allowed. Try to do these checks as early in the page as possible.
Simon