-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriceapp.php
47 lines (37 loc) · 1.22 KB
/
priceapp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
include 'db.php';
$msisdn = $_GET["msisdn"]; //Sender's Phone Number
$content = $_GET["content"]; // Content of the SMS
/*
Log request to a file
*/
$fp = fopen('request.log', 'a') or die("Can't open file.");
fwrite($fp, $msisdn . "\t");
fwrite($fp, $content . "\n");
fclose($fp);
/*
We will convert the contents from string to array so we can separate each field and fetch it from the database
*/
$content_array = explode(" ",$content);
$array_length = sizeof($content_array);
if ($array_length<3) {
$reply="You have sent a wrong command. Correct command is PRICE Manufacturer ModelNo. eg. PRICE Nokia E71";
}
else {
/* First argument is the manufacturer name and what follows is considered as the model number */
$manufacturer = $content_array[1];
$model = "";
for ($i=2; $i<=$array_length; $i++)
{
$model .= $content_array[$i] . " ";
}
$model=trim($model);
$reply=db_reply($manufacturer,$model);
}
/* Adding our name */
$reply .= " \n - Brought to you by www.onlygizmos.com";
/* store the sender's number and reponse in the variable to be sent to the api, json encode it and send it. */
$response = array('msisdn'=>$msisdn, 'content'=>$reply);
$json_response = json_encode($response);
echo "[$json_response]";
?>