> Hello World !!!

     

@syaku

PHP json2xml 사용법 및 XE 로그인연동 : json2xml , XpressEngine

written by Seok Kyun. Choi. 최석균

 XE 로그인 연동

* 경고: 본 소스는 보안상 문제가 있습니다. 로그인 연동에 필요한 값은 POST 로 넘겨 받고, 암호화 처리하는 것이 올바른 방법입니다.
타 사이트에서 XE 와 로그인 연동하기 위한 예제 소스입니다.
아래의 소스는 익스프레스엔진 하위 폴더에 존재해야 한다. /xe/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta content="Seok Kyun. Choi. (http://syaku.tistory.com)" name="Programmed" />
  <meta content="no" http-equiv="imagetoolbar" />
  <title></title>
  <script type="text/javascript" language="javascript" src="./common/js/jquery.js"></script>
</head>
<body>

<?php
$user_id = $_GET['user_id'];
$password = $_GET['password'];
?>

<script type="text/javascript">

/*  This work is licensed under Creative Commons GNU LGPL License.

  License: http://creativecommons.org/licenses/LGPL/2.1/
   Version: 0.9
  Author:  Stefan Goessner/2006
  Web:     http://goessner.net/ 
*/
function json2xml(o, tab) {
   var toXml = function(v, name, ind) {
      var xml = "";
      if (v instanceof Array) {
         for (var i=0, n=v.length; i<n; i++)
            xml += ind + toXml(v[i], name, ind+"\t") + "\n";
      }
      else if (typeof(v) == "object") {
         var hasChild = false;
         xml += ind + "<" + name;
         for (var m in v) {
            if (m.charAt(0) == "@")
               xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
            else
               hasChild = true;
         }
         xml += hasChild ? ">" : "/>";
         if (hasChild) {
            for (var m in v) {
               if (m == "#text")
                  xml += v[m];
               else if (m == "#cdata")
                  xml += "<![CDATA[" + v[m] + "]]>";
               else if (m.charAt(0) != "@")
                  xml += toXml(v[m], m, ind+"\t");
            }
            xml += (xml.charAt(xml.length-1)=="\n"?ind:"") + "</" + name + ">";
         }
      }
      else {
         xml += ind + "<" + name + ">" + v.toString() +  "</" + name + ">";
      }
      return xml;
   }, xml="";
   for (var m in o)
      xml += toXml(o[m], m, "");
   return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
}

$(function() {

  var data = {

    "methodCall":{
      "params":{
        "_filter":{"#cdata":"widget_login"},
        "user_id":{"#cdata":"<?php echo $user_id?>"},
        "password":{"#cdata":"<?php echo $password?>"},
        "module":{"#cdata":"member"},
        "act":{"#cdata":"procMemberLogin"}
      }
    }

  };

  var xml =  json2xml(data);

  $.ajax({
    url: "index.php",
    type: "POST",
    data: xml,
    dataType : "xml",
    contentType:'text/plain',
    success : function() {
      // 로그인 처리후 돌아갈페이지
      document.location.href = "/";
    }
  });
});

</script>
</body>
</html>


Syaku Blog by Seok Kyun. Choi. 최석균.
posted syaku blog


http://syaku.tistory.com