inbound sms in php


The sms gateway as system like inbound and outbound sms in which out bound sms used to send sms to number through http ,we usually get service code in any language like php,python,asp provided by sms gateway api provider.But inbound is like to send msg from mobile to http system service is not provided,they will provide URL like example.com/response.php to receive parameter by get or post method so we receive http request write down in text file like in code below.Make sure give right permission to write on text file.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 

<style type="text/css">
table.gridtable {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
color:#333333;
    border-width: 1px;
    border-color: #666666;
    border-collapse: collapse;
}
table.gridtable th {
    border-width: 1px;
padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #ebf4fb;
}
table.gridtable td {
    border-width: 1px;
padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #ffffff;
}
</style>

</head>
<body>

<?php

if( $_POST!=0||$_POST!=null){
    $dcs=urldecode($_POST['dcs']);
    $msgid =urldecode($_POST['msgid']);
   $sender = urldecode($_POST['sender']);// do not need to change
    $receiver = urldecode($_POST['receiver']); // do not need to change
        $text = urldecode($_POST['text']); // do not need to change
//$array = $_['text'];
$filename = "messages.txt";
    if ($from == "") {

    } else {
        $f=fopen("$filename","a");
        fwrite($f,"$dcs;$msgid;$sender;$receiver;$text;\r\n");
        fclose($f);
    }

    
    if (file_exists($filename)) {
        echo "<b>Message</b>";
        echo "<table class='gridtable'>";
        echo "<th>#</th><th>dcs</th><th>msgid</th><th>sender</th><th>receiver</th><th>text</th>";
        
        $lines = file($filename);
        foreach($lines as $line_num => $line){
        
            $xl = explode(";", $line);
            $rnr++;
            //var_dump($xl); echo '</br>';
        echo "<tr><td>$rnr</td><td>$xl[0]</td><td>$xl[1]</td><td>$xl[2]</td><td>$xl[3]</td><td>$xl[4]</td></tr>";
        }
        
        echo "</table>";
    } else {
        echo "<b>none</b>";
    }

}else{
echo "<hr><a href=\"response.php\">sms</a>";
}
?>

</body>
</html>