2

I have a script in second life building a json string which is base64 encoded and sent to a PHP script.

Login(string action)
{
    string json_string = "{\"Action\": \""+action+"\", \"Name\": \""+simName+"\", \"OwnersKey\": \""+ (string)llGetOwner() +"\", \"ObjectID\": \""+ (string)objectID +"\", \"ParcelName\": \""+ parcelName +"\"}";
    string data = "Data=" + llStringToBase64(json_string);
    toWebPage(data);
}

toWebPage(string params)
{
    params += "&FromSL=true";
    string tst = "";
    if(DEBUG)
    {
        tst = "/tst";
    }
    myRequest = llHTTPRequest(URL + PRODUCTNAME + tst + "/"+controller+".php",
  [HTTP_METHOD, "POST",
   HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
   params);
}

There are two times I call the Login script.

Login("RegisterTower");

creating the json string

{"Action": "RegisterTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost Lands~"}

and

Login("CheckInTower");

creating the json string

{"Action": "CheckInTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost Lands~"}

These json strings a base64 encoded and sent to the php script. The first script they hit is Main.php

<?php
include_once "Controller.php";
$params = $_GET;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $params = $_POST;
}
Controller::Process($params);
?>

Controller is as such

<?php
include_once 'Common.php';
include_once 'Entities.php';
include_once 'Database.php';

<?php
class Controller
{
    public static function Process($data)
    {
        echo base64_decode($data["Data"]);
    }
}
?>

When I check the results I get

{"Action": "RegisterTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost Lands~"}
{"Action": "CheckInTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost LandsHŸ

Why does the second json string decode with

"~Lost LandsHŸ

when the first did it

"~Lost Lands~"}

UPDATE: As suggested by Decent Dabble The contents of $data["Data"] each time is

eyJBY3Rpb24iOiAiUmVnaXN0ZXJUb3dlciIsICJOYW1lIjogIktvcnp1biIsICJPd25lcnNLZXkiOiAiOGQxM2ZhMGYtYjU0ZC00M2M5LTg0MjYtZjdjYjI4ZjkzY2ZkIiwgIk9iamVjdElEIjogImJlNDg4NWE0LWE1OTYtNmE2NS05MjVlLTQ3MGYxNDllOWI2MyIsICJQYXJjZWxOYW1lIjogIn5Mb3N0IExhbmRzfiJ9 

and

eyJBY3Rpb24iOiAiQ2hlY2tJblRvd2VyIiwgIk5hbWUiOiAiS29yenVuIiwgIk93bmVyc0tleSI6ICI4ZDEzZmEwZi1iNTRkLTQzYzktODQyNi1mN2NiMjhmOTNjZmQiLCAiT2JqZWN0SUQiOiAiYmU0ODg1YTQtYTU5Ni02YTY1LTkyNWUtNDcwZjE0OWU5YjYzIiwgIlBhcmNlbE5hbWUiOiAifkxvc3QgTGFuZHN In0=

I am assuming now i have posted this, the problem is the space at the end of the second one. The original data I send is

eyJBY3Rpb24iOiAiQ2hlY2tJblRvd2VyIiwgIk5hbWUiOiAiS29yenVuIiwgIk93bmVyc0tleSI6ICI4ZDEzZmEwZi1iNTRkLTQzYzktODQyNi1mN2NiMjhmOTNjZmQiLCAiT2JqZWN0SUQiOiAiYmU0ODg1YTQtYTU5Ni02YTY1LTkyNWUtNDcwZjE0OWU5YjYzIiwgIlBhcmNlbE5hbWUiOiAifkxvc3QgTGFuZHN+In0=

So now how do I solve that???

Tom Hanson
  • 873
  • 10
  • 39
  • Can you show use the contents of `$data["Data"]` from both times *before* you `base64_decode()` them? – Decent Dabbler Nov 29 '17 at 10:05
  • 1
    Updated with results – Tom Hanson Nov 29 '17 at 10:11
  • Yep, you're assumptions are very likely to be correct, as I was just looking into the `base64_decode()` documentation for an earlier question, where [this comment on PHP's documentation](https://secure.php.net/manual/en/function.base64-decode.php#102113) offered a (likely) fix: replace spaces with `+` signs. That's why I asked for the base64 encoded data. :) – Decent Dabbler Nov 29 '17 at 10:16
  • `str_replace(' ','+',$str)`? – Professor Abronsius Nov 29 '17 at 10:25
  • Thanks Decent Dabbler, can you add your comment as an answer so I can tick it :D – Tom Hanson Nov 29 '17 at 10:26
  • @TomHanson if the question is solved and Dabbler doesn't post his solution as an answer, you could add an answer yourself (and later accept it). – domsson Oct 21 '19 at 17:45

0 Answers0