Hi
I am tyring to encrypte variables because I dont want user anyone know the variabeles that pass through url.
let say i have variabels $id and $phone which pass through ..
index.php?file=user&id=121&phone=121
I want encrypte all these information
let say to
index.php?file=encryptefils
(ie.index.php?file=3424XCDFDfd545V)
Then i decrypte the $file variabls
what i want just some suggestions or coments on weather it i is good method or not.
Here is one example
<?
function index(){
//test variable that is sppose to be in the url
$old="var1|23|var2|2";
$new=encoded($old);
echo"Old :$old<hr> New:$new<hr><a href=$_SERVER[PHP_SELF]?op=link2&sid=$new>Go to link2 where you decrypte the variables</a>";
}
function link2(){
echo"This is link 2. Go to <a href=$_SERVER[PHP_SELF]>home</a><hr>";
$decoded=decoded($_GET["sid"]);
echo"Decoded:$decode<hr>";
$array=array();
$array=explode("|","$decoded");
$var1=$array[1];
$var2=$array[3];
echo"Var1: $var1<br>Var 2: $var2";
}
// from php.net
function encoded($ses)
{
$sesencoded = $ses;
$num = mt_rand(3,9);
for($i=1;$i<=$num;$i++)
{
$sesencoded =
base64_encode($sesencoded);
}
$alpha_array =
array('Y','D','U','R','P',
'S','B','M','A','T','H');
$sesencoded =
$sesencoded."+".$alpha_array[$num];
$sesencoded =
base64_encode($sesencoded);
return $sesencoded;
}//end of encoded function
// from php.net
function decoded($str)
{
$alpha_array =
array('Y','D','U','R','P',
'S','B','M','A','T','H');
$decoded =
base64_decode($str);
list($decoded,$letter) =
split("\+",$decoded);
for($i=0;$i<count($alpha_array);$i++)
{
if($alpha_array[$i] == $letter)
break;
}
for($j=1;$j<=$i;$j++)
{
$decoded =
base64_decode($decoded);
}
return $decoded;
}//end of decoded function
switch($_REQUEST["op"]){
default:
index();
break;
case"link2":
link2();
break;
}
?>