Simple encryption in PHP

后端 未结 3 1219
一个人的身影
一个人的身影 2020-12-28 10:23

I\'m building a with-source system which I am giving out on the \'net for providing adoptable virtual pets. The system will be owned mainly by kids. Since I want it to be us

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 11:09

    You are looking for "one time padding" encryption. It takes a key and does modulus addition to characters to create the encrypted string.

    function ecrypt($str){
      $key = "abc123 as long as you want bla bla bla";
      for($i=0; $i

    So that's simple string encryption. What I would do is serialize the array of the user's parameters and pass it as a variable in the link:

    $arr = array(
      'pet_name'=>"fido",
      'favorite_food'=>"cat poop",
      'unique_id'=>3848908043
    );
    $param_string = encrypt(serialize($arr));
    
    $link = "/load_pet.php?params=$param_string";
    

    In load_pet.php you should do the opposite:

    $param_string = $_GET["params"];
    $params = unserialize(decrypt($param_string));
    

    Bam.

提交回复
热议问题