当我从带有httpPost的android设备调用它时,我的PHP代码出错

i am written a program for android devices that sends call logs to my database in my host. i use httpPost method to do this and other side i have a php code.

when i try to run this code in request i get a page in this mainly i see this :

500 Internal Server Error

and in Apache Error Log i give this error :

PHP Startup: Suhosin Extension does not officially support PHP 5.2 and below anymore, because it is discontinued. Use it at your own risk. in Unknown on line 0

my host provider don't permission me to directly change php.ini file.

some of my php code side :

function callLogSyncToCount()
{
global $serverAddress, $DBusername, $DBpassword, $DBname;
$userID = $_POST['userID'];
$data   = $_POST['data'];
$logs = explode('`second`', $data);
foreach($logs as $item)
{
    //list($number, $duration, $date, $type) = explode("`first`", $item);

    $counter = 0;

    $con = mysql_connect($serverAddress, $DBusername, $DBpassword) or die (mysql_error());
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
        return false;
    }
    mysql_select_db($DBname, $con);mysql_query("SET NAMES 'utf8'");
    $result = mysql_query("SELECT * FROM `call_log` WHERE `user_id` = '".$userID."' AND `number` = '".$number."' AND `date` = '".$date."' AND `type` = '".$type."'") or die (mysql_error());
    while($row = mysql_fetch_array($result))
    {
        $counter++;
    }
    if ($counter < 1)
    {
        mysql_query("INSERT INTO `call_log`(`user_id`, `date`, `duration`, `number`, `type`) VALUES ('".$userID."', '".$date."', '".$duration."', '".$number."', '".$type."')") or die (mysql_error());
    }
    mysql_close($con) or die (mysql_error());
}
return true;

}

some of my androide side code is :

private class SyncToCount extends AsyncTask<String, Void, String> {
    @SuppressLint("SimpleDateFormat")
    @Override
    protected String doInBackground(String... param) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(param[0]);
        SimpleDateFormat mySQLFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mySQLFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        long ID = Long.parseLong(param[1]);
        List<callLogType> calls = new ArrayList<CallLogUtility.callLogType>();

        calls = getCallList();
        String sendStr = "";
        globalVars.syncLogSize = calls.size();
        try {
            int j = 0;
            for(int i = 0; i < calls.size() && j < 20; i++) 
            {           
                if(calls.get(i).ID <= ID)
                    continue;
                j++;
                sendStr += calls.get(i).PhoneNumber + "`first`";
                sendStr +=Integer.toString(calls.get(i).Duration)+ "`first`";
                Date newDate = new SimpleDateFormat("d MMM yyyy hh:mm:ss z").parse(calls.get(i).Date);
                sendStr +=mySQLFormat.format((newDate))+ "`first`";
                sendStr +=Integer.toString(calls.get(i).Type)+ "`second`";
                globalVars.syncLogUntil+=1;
            }

        } catch (Exception e) {

        }
        try
        {
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("syncType", "calllogtocount"));
            nameValuePairs.add(new BasicNameValuePair("userID", param[1]));
            nameValuePairs.add(new BasicNameValuePair("data", sendStr));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            @SuppressWarnings("unused")
            HttpResponse response = httpclient.execute(httppost);

            BufferedReader in = new BufferedReader
            (new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
        }
        catch(Exception ex)
        {
        }
        return null;
    }       
}

this code don't work but my log in code works properly whit syntax like this and from this android code and that server and php and database.

help me i am ambiguous whit php and android ...

My instinct here is that you have not initialized the variables that you are using and this is upsetting things. I am not following where the named variables are coming from I am assuming that there is no Register_globals going on here (hope not). If you are it would explain why the system is checking an error over PHP version in use although I think that is just a side effect of the commented out line.

My further instinct is to worry about the unescaped data being placed into the SQL statement but that could be a distraction if mysql_real_escape_string() can be used then it should to protect against (deliberate) bad user data as it's not. I wonder if you sent malformed data (from say a form) if you could trigger the error (or cause other errors like SQL injection)?

Have you tested the PHP with a basic form that submits the data exactly as you expect it? That would allow you to debug output data to a file or screen to see what is happening but it looks from here that the PHP code needs those variables explicitly set with values from $_POST.

It looks to me like the variables need filling but as the list line has been commented out that is not happening which could leave you with uninitialized variables which may or may not be upsetting things.

Other than that if you block comment out the code inside the foreach does it return true? If yes then I might be right and the problem is inside there so bring it back bit by bit until the error throws. If not then it is outside and you have eliminated half your code from you inquiries.

I hope that gives you something to work with. All the best with finding the source of your woes.