Server answering info requests from other sites?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Seymour Clufley
Forum Newbie
Posts: 15
Joined: Wed Mar 19, 2008 8:34 am

Server answering info requests from other sites?

Post by Seymour Clufley »

I'm building a site where registered members play Flash games. The scores are recorded.

The site is run by a server program which I'm writing in PureBasic. This program responds to Ajax requests from pages and periodically recounts scores and calculates averages etc.

Now, let's say "Gilbert" wants to show off his top 10 scores on his own website. He doesn't want to have to change his HTML every day; he wants the information to be up-to-date automatically. That means requesting the information from my site.

But, it is vital that only Gilbert's homepage gets his information from my site. So, I need some way to verify that it's Gilbert's homepage. He can set his homepage in his user profile, then if requests come from that site asking for Gilbert's info, they'll be accepted.

Any help or advice with this would be greatly appreciated.

Thanks for reading,
Seymour.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Server answering info requests from other sites?

Post by Benjamin »

You essentially need to create an API.

Create a cron job which executes a php script every 12 to 24 hours.
Create a php script which will pull the scores from your server. The script can post a user name and password.
Save the scores as xml, json or a serialized array in a text file.
Create code which will read the data from the text file and display it on the web page.

On your server:
Create a php script which will authenticate requests from the cron scripts. After authentication, return the scores in xml, json or a serialized array.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Server answering info requests from other sites?

Post by Jonah Bron »

Or, give a javascript tag.

Probably the easiest option (for the user) would be to give him a dynamically generated badge in the form of an image (e.x. http://example.com/badge.png?user=gilbert)
Seymour Clufley
Forum Newbie
Posts: 15
Joined: Wed Mar 19, 2008 8:34 am

Re: Server answering info requests from other sites?

Post by Seymour Clufley »

Benjamin wrote:You essentially need to create an API.

Create a cron job which executes a php script every 12 to 24 hours.
Create a php script which will pull the scores from your server. The script can post a user name and password.
Save the scores as xml, json or a serialized array in a text file.
Create code which will read the data from the text file and display it on the web page.

On your server:
Create a php script which will authenticate requests from the cron scripts. After authentication, return the scores in xml, json or a serialized array.
I'm sorry, I don't understand.
Create code which will read the data from the text file and display it on the web page.
PHP code?
On your server:
Create a php script which will authenticate requests from the cron scripts. After authentication, return the scores in xml, json or a serialized array.
This is the bit that confuses me. I thought the cron scripts were writing scores to XML/JSON, not making info requests?

And also, how would one of my members make info requests with this system?
Seymour Clufley
Forum Newbie
Posts: 15
Joined: Wed Mar 19, 2008 8:34 am

Re: Server answering info requests from other sites?

Post by Seymour Clufley »

Jonah Bron wrote:Or, give a javascript tag.

Probably the easiest option (for the user) would be to give him a dynamically generated badge in the form of an image (e.x. http://example.com/badge.png?user=gilbert)
I'm not sure what you mean by this.

It needs to be secure, in that someone can't download my member's homepage and get any login details that are stored on it for making info requests to my site.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Server answering info requests from other sites?

Post by Jonah Bron »

Calling that image would return an image that looks something like this:

[syntax]
_____________________
| User Gilbert |
|Top Tetris Score: 300|
|Top Pong Score: 100|
|_____________________|
[/syntax]

Then they can just put the picture wherever they want. Is that how you want it?
Seymour Clufley
Forum Newbie
Posts: 15
Joined: Wed Mar 19, 2008 8:34 am

Re: Server answering info requests from other sites?

Post by Seymour Clufley »

Right, I understand now. Unfortunately, delivering the info as a graphic wouldn't solve the security issue.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Server answering info requests from other sites?

Post by Jonah Bron »

So, you just want to make sure that only Gilbert can display the graphic (or however you transmit the data), right? Why?
Seymour Clufley
Forum Newbie
Posts: 15
Joined: Wed Mar 19, 2008 8:34 am

Re: Server answering info requests from other sites?

Post by Seymour Clufley »

Jonah Bron wrote:So, you just want to make sure that only Gilbert can display the graphic (or however you transmit the data), right? Why?
Well, when I said my website is a games website, that wasn't true. It's just easier to explain that way.

Stuff that members do on my site, they may or may not want everyone to know about. It's essentially a discussion website. People don't always want their views being aired all over the Internet.

But some people do - and that's why I'm offering them this info service.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Server answering info requests from other sites?

Post by Eran »

There are several approaches you can take to achieving this. One would be to build an API to your system, as Benjamin suggested. API are mostly useful to other developers, so that might not be what you are after. The other is to create an embeddable piece of code that users can copy and put on their site to display the scores. You can achieve that in several ways - using a javascript tag as Jonah Bron suggested, using an Iframe or using a Flash embed. I recently wrote an article on the latter approaches that might be of interest to you - http://www.techfounder.net/2010/02/05/c ... e-widgets/

Regarding security - the only way to limit access to the data only to authenticated parties is using server side code - which means only though an API can you achieve complete security. Client-side widgets (javascript, iframe, flash) usually identify using some form of unique string (often a hash) or integer uniquely identifying the user. Being client-side though, means that everyone visiting the user's site can copy the widget and display it themselves
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Server answering info requests from other sites?

Post by Jonah Bron »

But if not everyone wants the info all over, you can give the user the option to enable/disable it. That way, I can't just replace "gilbert" with "mike", because mike has it disabled; and if he doesn't, it's okay because he doesn't care.
Seymour Clufley
Forum Newbie
Posts: 15
Joined: Wed Mar 19, 2008 8:34 am

Re: Server answering info requests from other sites?

Post by Seymour Clufley »

Jonah Bron wrote:But if not everyone wants the info all over, you can give the user the option to enable/disable it. That way, I can't just replace "gilbert" with "mike", because mike has it disabled; and if he doesn't, it's okay because he doesn't care.
Thanks Jonah, that's the simplest idea. :) It doesn't stop people using the service who aren't registered members, but it does protect members who want their opinions kept private.

I'd like to investigate Benjamin's suggestion about "essentially creating an API", but unfortunately I'd need him (or someone else who knows about this stuff) to explain his summary, as I can't follow it the way he wrote it.

Meantime I'll look into the widgets idea that Pytrin suggested.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Server answering info requests from other sites?

Post by Jonah Bron »

The API can be quite simple; how about a page that responds with a JSON file, that the user calls with cURL? But as pytrin stated, that wouldn't be suitable for most users.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Server answering info requests from other sites?

Post by Eran »

If you want to go about creating an API, the most straightforward way to learn would be to try using other services' APIs. Try Twitter's and Facebook's API, Amazon's API, Paypal API and so forth. You'll see a lot of different approaches for request and response formats, but the basics are the same.
I'd recommend doing something similar to Twitter's API, as it's relatively very convenient to use (aside from the authentication part)
Post Reply