RyanMinor Posted November 13, 2011 Share Posted November 13, 2011 I want to create a REST API for my website. What I want to do is to display advertisements from my database on websites that I sell to clients. Their website will call my database for advertisements to display on their websites. Also, I am performing a site validity check where the client's site would send the site URL, site name, and site token to my database for validation. If it returns false then the site will not display as it will be invalid according to my database. I've been Googling this topic all day, but cannot seem to get my head around it. I want to set an API key on my website so that not just anybody can be querying my database. For the advertisement query, no parameters need to be sent from the client websites to my database. Can anyone offer some advice on how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/251078-creating-a-rest-api/ Share on other sites More sharing options...
ignace Posted November 15, 2011 Share Posted November 15, 2011 <img src="http://yourwebsite.com/adverts-api.php?key=123" alt=""/> Verify if the referrer(?) matches the 123 key. Quote Link to comment https://forums.phpfreaks.com/topic/251078-creating-a-rest-api/#findComment-1288502 Share on other sites More sharing options...
requinix Posted November 15, 2011 Share Posted November 15, 2011 Here's a question: how secure does this need to be? Quote Link to comment https://forums.phpfreaks.com/topic/251078-creating-a-rest-api/#findComment-1288509 Share on other sites More sharing options...
ignace Posted November 16, 2011 Share Posted November 16, 2011 It was late when I posted this. I now realize a far better option would be to not expose the API at all and let the API return a path to an image. Something like: $image_url = file_get_contents('http://my-api-website.com/adverts-api.php?host=the-host-website&session=' . $somesessionid); echo '<img src="', $image_url, '" alt=""/>'; Quote Link to comment https://forums.phpfreaks.com/topic/251078-creating-a-rest-api/#findComment-1288635 Share on other sites More sharing options...
RyanMinor Posted November 18, 2011 Author Share Posted November 18, 2011 Thanks everyone for the replies. I downloaded an eBook ob REST and did some more research to find that it would probably just be better to use file_get_contents(). I implemented this and it works good. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/251078-creating-a-rest-api/#findComment-1289324 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.