Hi Fox & Jkofsky,
Thank for your reply.
I did as per mention by Fox but trick didnt work as well.but Jkofsky trick was works as well by changing this
<id:[\-]?\d+> to <id:[\-]?\w+>. Then the rest i did as per FOx mentioned earlier by changing the id encryption in controller action method.
BUT now the issue is ,its not working for all other encrypted id and only working for certain encrypted id.
such as :
When i try to access this below url no issue at all.able to view the data.
a.)http://localhost/workspace2/yii/organisation/view/TXgcClNtqaJUozJoRNoGn6MOnBpVI3j3KuTzMfI_AAY
b.)http://localhost/workspace2/yii/organisation/view/y77aSykIATYWJDC64QFROfMuXoJG84e2TCjho9lwJAY
for the below url i cant view the data ,its throw this error :Error 400 Your request is invalid.
c.)http://localhost/workspace2/yii/organisation/view/ydNCaNB-9suxDEqD4qWDCsrAZO_yWvHboX1hqKZk2gw
d.)http://localhost/workspace2/yii/organisation/view/6icsR7MPn2pRBpJLLmG4eNZ1ZKFH4m-561zpxvMAdVU
Controller View
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$id = EncrptionUrl::decode($id);
$model2 = new Contactperson('searchOrganisation');//contact person
$model2->unsetAttributes(); // clear any default values
if(isset($_GET['Contactperson'])){
$model2->attributes = $_GET['Contactperson'];
}
$this->render('view',array(
'model'=>$this->loadModel($id),'model2'=>$model2
));
}
Main.config
// uncomment the following to enable URLs in path-format
//Hide the index.php to secure shorter URL path
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
// 'caseSensitive'=>false,
//'urlSuffix'=>'.html',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/<action>',
// '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>/<id:[\-]?\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
EncrptionUrl class file.
class EncrptionUrl {
//private static $skey = ''; // you can change it 32 chars
public function safe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}
public function safe_b64decode($string) {
$data = str_replace(array('-','_'),array('+','/'),$string);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
return base64_decode($data);
}
public static function encode($value){
$skey = Yii::app()->params['encrypt_url_pathid'];
if(!$value){return false;}
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $skey, $text, MCRYPT_MODE_ECB, $iv);
return trim(EncrptionUrl::safe_b64encode($crypttext));
}
public static function decode($value){
$skey = Yii::app()->params['encrypt_url_pathid'];
if(!$value){return false;}
$crypttext = EncrptionUrl::safe_b64decode($value);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $skey, $crypttext, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}