Created
September 16, 2020 15:14
-
-
Save 3lpsy/5f04e3bc35aa86e343c6123a901c7a3e to your computer and use it in GitHub Desktop.
Serialization snippets for php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Need to split into files. Changes made need to be made. | |
/* this portion should go in serial.php */ | |
<?php | |
class Message { | |
/* Insert rest of class from SDK docs */ | |
} | |
/* get first cli argument */ | |
$messageText = $argv[1]; | |
/* init object and assign text property */ | |
$msg = new Message(); | |
$meg->text = $messageText; | |
/* serialize the Message object */ | |
$serMsg = serialize($msg); | |
/* convert to b64 */ | |
$b64Val = base64_encode($serMsg); | |
/* output */ | |
echo "Serialization Text: \n"; | |
echo $messageText; | |
echo "\n\n"; | |
echo "Deserialized Result:\n"; | |
var_dump($serMsg); | |
echo "\n\n"; | |
echo "Base64 Payload: \n"; | |
echo $b64Val; | |
echo "\n"; | |
?> | |
/* this portion should go in deserial.php */ | |
<?php | |
/* accept the base64 encoded value as the first arg */ | |
$b64Val = $argv[1]; | |
/* convert the value to a string */ | |
$strVal = base64_decode($b64Val); | |
/* output */ | |
echo "Deserializing Value: \n"; | |
echo $strVal; | |
echo "\n\n"; | |
/* deserialize string */ | |
$desVal = unserialize($strVal); | |
/* print out value using val_dump */ | |
echo "Deserialized Result:\n"; | |
var_dump($desVal); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment