Jump to content

Recommended Posts

I have tons of lead verification information stored in a database on my server for emails, phone, name, address and large blacklists etc.

 

I have created a simple way to call the info so it spits out as the ONLY output from a query is a single number. Either 0 for valid, 1 for fraud, 2 for incorrect.

 

I want to start with just email information for this example...

 

So I want people to be able to call my page on their registration forms to check if they have valid users.

 

I tried file_get_contents with the url + variable appended to be checked but it only spits out the answer you would get with no variable appended.

 

Plus I also have the problem as the form submit, how can they click submit once, have it check the info, then actually submit if its valid but return an error if not?

 

What is the best way to do this?

Basic cross domain server calls is called HTTP request.  You would handle it just like any other form submission.  If it were me, and other people were calling my domain for specific requests (like you describe), I would write an API for the purpose.

 

1. User from site A submits form to site A

2. Site A request a check from site B

3. Site B validates request, and outputs status of request.

4. Site A checks response from B, and outputs desired results.

 

You shouldn't need anything other than file_get_contents() if fopen wrappers are on, or cURL if you need more functionality.

I tried file_get_contents with the url + variable appended to be checked but it only spits out the answer you would get with no variable appended.

Then you need to debug the script, and find out why it does that.

 

Hope this helps, if you give a little current code, I could probably be more helpful.

Thanks that was helpful! I got it working, I just wasn't sure if I was going in the right direction.

 

No idea how to write an API. But doesn't the API just spit out the info on the page pretty much like what I am doing?

 

Also I am trying to make this pretty. (ie short) because since its a service, I am going to have all sorts of people putting this code on their pages, right now it works but its a cURL along with an if statement for the error outputs. So I still need to figure out if there is anything I can do in this respect too.

Think of an API as a set of functions.  Just as each function in PHP has a signature*, so do API calls.

 

*A function signature consists of: the function's name, the type and number of its arguments, and its return type.  You can see how this looks in the PHP online documentation.  An example:

 

string substr ( string $string , int $start [, int $length ] )

 

This tells us that the substr function has two required arguments - $string (which is a string) and $start (which is an integer) - and one optional argument - $length (which is also an integer).  We can also see that the function returns a string.

 

An API is similar, except it uses HTTP.  You can have a signature like:

 

mixed object - getuser/{id:int}

 

This would mean that there's an API call named 'getuser' that takes an integer id as a parameter, and returns a user object.  Keep in mind that that's just the call's signature.  Invoking it would mean using the URL example.com/getuser/23 or something along those lines.  Its return data would likely be a JSON object, or maybe some XML that could be parsed.  Why that and not raw PHP?  Because the whole idea of an API is that any service can make requests.  Because of that, the data sent back to the service needs to be platform agnostic.

 

Good APIs tend to be RESTful, which is really just a fancy way of saying they use HTTP verbs (like GET and POST) according to the HTTP spec.  So, GET for retrieving data, POST for adding data, DELETE for removing data, etc. 

 

Hope this helps!

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.