开发者

Accessing xml using user's cookies

For a game-related project.

To a开发者_JAVA技巧ccess game data, the user has to "authorize" access. To do this, they visit a page on the site, which sets 3 cookies on the user's PC.

When the user then views certain XML URLs, the game server checks these cookies are correct, and returns the information required.

My question is, how do I parse these XML files using the user's cookies, to add styling to the data etc?

If I use cURL to load the URLs, and CURLOPT_COOKIE to pre-determine the relevant cookies, it returns the information correctly.

However, I will not know the user's cookies, as they are only valid for the game's domain.

I'm certain this is possible, although perhaps not through this method, as it has been done before using the same data.

The cookies set are:

toolbar_code = 19 digit auth code
toolbar_hash = 19 digit hashed username
toolbar_remember = true


You can't read XML cross-domain (without CORS anyway and that's not mature enough yet).

The simplest way to have a remote script that checks cookies and returns data to a caller site is to point a <script> to the remote site and have JavaScript execute in that, that gives the caller data. The normal way to do this is JSONP.

Client-side:

<script type="text/javascript">
    function receiveData() {
        ...do something...
    }
</script>
<script type="text/javascript" src="http://gamedataserver/getdata.php?jsonp=receiveData"></script>

Server-side:

<?php
    header('Content-Type: text/javascript');
    header('Cache-Control: no-cache');
    if (...user auth is OK...) {
        $callbackfn= preg_replace('/[^a-z_]/', '', $_GET['jsonp']);
        $json= json_encode(...game data...);
        echo "$callbackfn($json);";
    }
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜