Jump to content

Recommended Posts

So I'm writing an api that my clients can use in their sites. I don't want to give them direct access to the code.

 

I have the script on api.XXXXXX.com

 

index.php contains:

 

 

 

<?php

require_once('base.php');
require_once('client.php');

class api extends client {

function __construct($config = null) {
return parent::__construct($config);
}
}
//....Other Code
?>

 

Is it possible for my clients to access the API class by including it in their site?

 

For example:

 

 

<?php

require_once('http://api.XXXXXX.com/index.php');

class service{
private $client;
function __construct() {
$this->client = new api();
}
}
//....Other Code
?>

Link to comment
https://forums.phpfreaks.com/topic/272930-cross-domain-script-access/
Share on other sites

Including via http doesn't work the same as a local include. The script your requesting through http will still be executed on the server it resides and any output included in your script. I.e. if someone includes your script you would have to print your class out for them to use it and even then it wouldn't work because you have dependencies they can't get their hands on for the same reason.

Creating an API can be easy, or hard depending on the type of API. Your best bet would be to get familiar with different types of API's and various web services, and find out which approach would be best for your needs.

 

The tutorials located here: http://www.webresourcesdepot.com/how-to-create-an-api-10-tutorials/ Will get you up and running in regards to building API's within just a couple of hours. Go through the first couple of tutorials, and all your questions will be answered and you'll have a good idea of how you want to put your API together.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.