Search code examples
phpcurlauthenticationexternalfile-get-contents

Extracting content from external website with authentication.


I'm currently trying to create a php script were the user has the ability to connect their user to several pages.

That was the idea.

What i'm trying to to is to check if the user is logged in to battlelog, and then grab his username.

I'm not sure if it's even possible... But i would appreciate any help I can get!


Solution

  • The main problem you're going to run into here is that most modern browsers employ cross-domain security to make sure that other websites or potentially malicious websites cannot gain illegal access to the user data in another browser window.

    What you're hoping to accomplish is what's called cross-site scripting. It is possible under certain circumstances. For instance, if battlelog exposes an API for another developer to access user data.

    This would of course involve server-side requests cross-domain, so you'd either need to use your server as a proxy, or use a JSONP web service where the response is sent in JSON format wrapped in a callback function.

    Accessing Data From PHP Scripts:

    Since you're using PHP, you'd need to have access to an API. PHP scripts cannot make requests to a browser, so battlelog would either need to have a plug-in architecture where you can embed scripts in their website, or they would need to expose an API for you to query from your server.