Following code will encrypt and decrypt as per your length and data:
You can easily pass it to URL
function randomstring_ENCRYPT($post_ad_id,$length){$characters = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$charactersLength = strlen($characters);
$randomString = ”;
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength – 1)];
}$encode =rtrim(strtr(base64_encode($randomString.$post_ad_id), ‘+/’, ‘-_’), ‘=’);
return $encode;
}
function randomstring_DESCRPT($data,$length){
$post_ad_id = base64_decode(str_pad(strtr($data, ‘-_’, ‘+/’), strlen($data) % 4, ‘=’, STR_PAD_RIGHT));
$pid = substr($post_ad_id, $length);
return $pid;
}
Advertisements