473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating a PHP API?

AaronL
99
Hello,

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
  1.   // *** REQUIRED CODE BY LAMBERT SOFTWARE ***
  2.   $ecommfetch = 'http://www.ecommphppro.com/' . $companycode . '/';
  3.  
  4.   // Get the function parameter
  5.   if ($_GET["fct"]!='')
  6.   { $function = $_GET["fct"]; }
  7.   else
  8.   { $function = 'catalog'; }
  9.  
  10.   // Determine which function we need from eCommPHP Pro
  11.   switch ($function)
  12.   {
  13.     case 'catalog':
  14.       $ecommfetch .= 'catalog.php';
  15.       break;
  16.  
  17.     case 'viewitem':
  18.       $ecommfetch .= 'catalog.php';
  19.       $parameters .= '&fct=viewitem';
  20.       break;
  21.   }
  22.  
  23.   // Now that we have the function, lets process the parameters passed.
  24.   if ($_GET["scat"]!='')
  25.   { $parameters .= '&scat=' . $_GET["scat"]; }
  26.  
  27.   if ($_GET["pg"]!='')
  28.   { $parameters .= '&pg=' . $_GET["pg"]; }
  29.  
  30.   if ($_GET["ppg"]!='')
  31.   { $parameters .= '&ppg=' . $_GET["ppg"]; }
  32.  
  33.   if ($_GET["srt"]!='')
  34.   { $parameters .= '&srt=' . $_GET["srt"]; }
  35.  
  36.   if ($_GET["srch"]!='')
  37.   { $parameters .= '&srch=' . $_GET["srch"]; }
  38.  
  39.   if ($_GET["inum"]!='')
  40.   { $parameters .= '&inum=' . $_GET["inum"]; }
  41.  
  42.   if ($_GET["vimgnum"]!='')
  43.   { $parameters .= '&vimgnum=' . $_GET["vimgnum"]; }
  44.  
  45.   // Now lets make sure the right delimiter is in place for the function
  46.   if (substr($parameters, 0, 1)=='&')
  47.   { $parameters = '?' . substr($parameters, 1); }
  48.   else
  49.   { 
  50.     if ($parameters!='')
  51.     { $parameters = '?' . $parameters; }
  52.   }
  53.  
  54.   // Add the parameters to the fetch URL
  55.   $ecommfetch .= $parameters;
  56.  
  57.   // Replace spaces with +
  58.   $ecommfetch = str_replace(" ", "+", $ecommfetch);
  59.  
  60.   // Go ahead and fetch the page now.
  61.   echo trim(file_get_contents($ecommfetch));
  62.  
Is there a way to do this better and not use
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.
Oct 15 '10 #1
3 1572
kovik
1,044 Expert 1GB
Building an API on the web is basically a means of allowing developers to access data the same way that they would through a web browser: requests and responses.
  • One way of accomplishing this is to allow server requests and responses where the developer posts data and receives data back, in the style of AJAX.
  • Another way is to allow socket connections for requests and responses. This is more responsive for the developer (though possibly less friendly to newer developers), but potentially more server intensive for you.

These methods shouldn't be language-specific.
Oct 15 '10 #2
AaronL
99
I see, what is AJAX exactly, I see that out there a lot.
Oct 16 '10 #3
kovik
1,044 Expert 1GB
AJAX is basically a method, using JavaScript, to request information via a HTTP request and receive a response. IT's called AJAX (Asynchronous JavaScript And XML) because the standard response used to be an XML document, though many developers are using JSON objects now.
Oct 16 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: rdsteph | last post by:
Python411 is a series of podcasts about Python, aimed at hobbyists and others who are learning Python. Each episode focuses on one aspect of learning Python, or one kind of Python programming, and...
6
by: owen | last post by:
Generally speaking, what does it mean when I see a "button" with red text showing this message instead of the control I've dragged onto the web form in Design View.? (But the page works fine at...
2
by: Pawan | last post by:
Hi Guys, I have this current assignment where I have to develop online forms for local municipal authorities. I have to use adobe acrobat to create online forms from PDFs (which I have never done...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
2
by: LIN | last post by:
Hello, Greetings. I am creating a web site which will contain lot of articles. I had been planning to create simple HTML page on the server everytime i posted a article (eg. article12.html )....
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
0
by: Ravi Ambros Wallau | last post by:
Hi: I've created a custom control - a grid that uses Infragistics to display some filters, the grid itself, and some buttons. Well, when using this control directly on WebForm, everything works...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.