@@ -233,16 +233,20 @@ public static function in_string($needle, $string) {
233233 } else return stripos ($ string , $ needle ) !== false ;
234234 }
235235
236- public static function save_session_result ($ data ) {
237- $ uuid = self ::uuid ();
238- $ _SESSION [$ uuid ] = json_encode ($ data );
236+ public static function save_session_result ($ data , $ key ) {
237+ $ json_data = json_encode ($ data );
238+ $ token = hash_hmac ('sha1 ' , $ json_data , $ key );
239+ $ _SESSION [$ token ] = json_encode ($ data );
239240
240- return $ uuid ;
241+ return $ token ;
241242 }
242243
243- public static function get_session_result ($ token ) {
244- $ data = isset ($ _SESSION [$ token ]) ? $ _SESSION [$ token ] : null ;
245- return json_decode ($ data );
244+ public static function get_session_result ($ token , $ key ) {
245+ $ json_data = isset ($ _SESSION [$ token ]) ? $ _SESSION [$ token ] : null ;
246+
247+ // verify data by token
248+ $ signature = hash_hmac ('sha1 ' , $ json_data , $ key );
249+ return $ signature === $ token ? json_decode ($ json_data ) : false ;
246250 }
247251
248252 public static function explode_ids ($ src , $ separator = '; ' ) {
@@ -642,19 +646,19 @@ public static function set_content_type($type = 'application/json') {
642646 header ('Content-Type: ' . $ type );
643647 }
644648
645- public static function encode_api_result ($ result , $ format = " json " ) {
649+ public static function encode_result ($ result , $ format = ' json ' ) {
646650 switch ($ format ) {
647- case " json " :
648- set_content_type (" application/json " );
649- return json_encode ($ result );
650- break ;
651- case " xml " :
652- set_content_type (" text/xml " );
653- $ xml = new XMLHelper (" Response " );
654- return $ xml ->to_xml ($ result );
655- break ;
651+ case ' json ' :
652+ self :: set_content_type (' application/json ' );
653+ echo json_encode ($ result );
654+ break ;
655+ case ' xml ' :
656+ self :: set_content_type (' text/xml ' );
657+ $ xml = new XMLHelper (' Response ' );
658+ echo $ xml ->to_xml ($ result );
659+ break ;
656660 default :
657- return $ result ;
661+ echo $ result ;
658662 }
659663 }
660664
0 commit comments