Reputation: 19826
I want to be able to send a parameter to a php page that contains a devices IMEI/MEID.
I then want the php page to take that IMEI parameter and check a list of IMEI's to see if the IMEI sent as a parameter from my Java mobile app is contained in a database, if it is then return true.
I only know the very basics of php but I believe this should be possible?
If so can anyone point me in the right direction of what php functions I should be looking into?
And also the best way to pass the parameter from java?
Upvotes: 1
Views: 759
Reputation: 181270
Yes, it's perfectly possible. You don't pass parameters to php functions. Instead of that, you use HTTP protocol to execute php scripts.
You need to execute a GET
HTTP command from your mobile device like this:
http://your.app.server.com/imei_script.php?imei=IMEI_VALUE
In your PHP script, you will have something simple like:
<?php
// to return plain text
header("Content-Type: plain/text");
$imei = $_GET["imei"];
// make a DB call to check if IMEI exists
// store "true" or "false" string in $retval
echo($retval);
?>
Your PHP script will reside in your application server (Apache with MOD_PHP). Refer to Apache's documentation to setup it with PHP support, and to learn where to place the script. You will have to add the DB part. There are lots of examples you can find on the internet (even in StackOverflow) to learn how to connect to a Database with PHP. They all depend on what database you connect to, so when you search (or ask in StackOverflow), make sure you specify what DB you are connecting to.
To invoke remote HTTP commands with Java ME you can use HttpConnection interface.
You will use something like:
String imei = ...;
String url = "http://your.app.server.com/imei_script.php?imei=" + imei;
// This will remotely call your PHP script with the IMEI parameter you need
HttpConnection c = (HttpConnection)Connector.open(url);
Upvotes: 2
Reputation: 240860
Make HTTP GET request to your php page from java app pass parameter to php page using
somePage.php?param1=value1
and on php page get this param as
<?php
echo($param1);
?>
Use this java-me code to make GET request
Upvotes: 1