I am so close to getting my big software project done, but I'm not satisfied on how one aspect works. The deal is, I want to have people use my software as a service without gaining access to my source code. I am to understand that if I develop my software as an API, I can do this.
My questions are:
How do I make an API in PHP?
- How do I send parameters to the API and get data back?
Here is my code on how I'm currently getting data from my software:
Expand|Select|Wrap|Line Numbers
- // *** REQUIRED CODE BY LAMBERT SOFTWARE ***
- $ecommfetch = 'http://www.ecommphppro.com/' . $companycode . '/';
- // Get the function parameter
- if ($_GET["fct"]!='')
- { $function = $_GET["fct"]; }
- else
- { $function = 'catalog'; }
- // Determine which function we need from eCommPHP Pro
- switch ($function)
- {
- case 'catalog':
- $ecommfetch .= 'catalog.php';
- break;
- case 'viewitem':
- $ecommfetch .= 'catalog.php';
- $parameters .= '&fct=viewitem';
- break;
- }
- // Now that we have the function, lets process the parameters passed.
- if ($_GET["scat"]!='')
- { $parameters .= '&scat=' . $_GET["scat"]; }
- if ($_GET["pg"]!='')
- { $parameters .= '&pg=' . $_GET["pg"]; }
- if ($_GET["ppg"]!='')
- { $parameters .= '&ppg=' . $_GET["ppg"]; }
- if ($_GET["srt"]!='')
- { $parameters .= '&srt=' . $_GET["srt"]; }
- if ($_GET["srch"]!='')
- { $parameters .= '&srch=' . $_GET["srch"]; }
- if ($_GET["inum"]!='')
- { $parameters .= '&inum=' . $_GET["inum"]; }
- if ($_GET["vimgnum"]!='')
- { $parameters .= '&vimgnum=' . $_GET["vimgnum"]; }
- // Now lets make sure the right delimiter is in place for the function
- if (substr($parameters, 0, 1)=='&')
- { $parameters = '?' . substr($parameters, 1); }
- else
- {
- if ($parameters!='')
- { $parameters = '?' . $parameters; }
- }
- // Add the parameters to the fetch URL
- $ecommfetch .= $parameters;
- // Replace spaces with +
- $ecommfetch = str_replace(" ", "+", $ecommfetch);
- // Go ahead and fetch the page now.
- echo trim(file_get_contents($ecommfetch));
file_get_contents? I want to create an asp compatible
way of getting data too so that I don't have to limit
my customers to just PHP servers.
If someone can explain this to me in details, I would
be forever grateful.