0

Hi i'm developing an android application in android studio in java that send sign up information to the server, i'm using volley library to make HTTP requests(GET method) and for my server side i'm coding with php to get information from client side.
my issue is when i send persian characters to the server by android devices with api 16 or lower the server get requests parameters content like this : ???? , i don't have this problem when i make requests from devices with api 17 and higher
i tried to send sign up information in JSON format but it did not work.

my php version 5.3.5 ,mySql 5.5.8 and android studio version 3.
this is my android client side code :

private void sendDataToServer() {

    SendDataObject dataObject = new SendDataObject();
    dataObject.setName(edtName.getText().toString());
    dataObject.setFamily(edtFamily.getText().toString());
    dataObject.setCodeMelli(edtCodeMelli.getText().toString());
    dataObject.setOstan(edtOstan.getText().toString());
    dataObject.setID(ID);





    String url = SplashActivity.SERVER_IP + "sign_up_users.php?name=" + edtName.getText()
            +
            "&family=" + edtFamily.getText().toString().trim() +
            "&codeMelli=" + edtCodeMelli.getText().toString().trim() +
            "&ostan=" + edtOstan.getText().toString().trim() +
            "&ID=" + ID;


    StringRequest getRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    if (response.toString().equals("true")) {

                        SplashActivity.USER_ID = ID;

                        Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
                        startActivity(intent);
                        setSharedPrefs();
                        overridePendingTransition(R.anim.slide_i_left,R.anim.slide_i_right);
                    }
                    else {
                        NoInternetDialog cdd = new NoInternetDialog(SignUpActivity.this);
                        cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                        cdd.show();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }
    );
    getRequest.setRetryPolicy(new DefaultRetryPolicy(18000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    RequestQueue requestQueue = Volley.newRequestQueue(SignUpActivity.this);
    requestQueue.add(getRequest);



}

and my php server side code sign_up_users.php :

<?php
    include 'connect.php';


    if (isset($_GET["name"]) && isset($_GET["family"]) && isset($_GET["codeMelli"]) && isset($_GET["ostan"]) && isset($_GET["ID"])) {
        $name = $_GET["name"];
        $family = $_GET["family"];
        $codeMelli = $_GET["codeMelli"];
        $ostan = $_GET["ostan"];
        $ID = $_GET["ID"];




        $stmt = $conn->prepare("UPDATE users SET name=:name ,family=:family, validation_status=1, codeMelli=:codeMelli , ostan=:ostan WHERE ID=:ID");

        $stmt->bindParam(':name',$name);
        $stmt->bindParam(':family',$family);
        $stmt->bindParam(':codeMelli',$codeMelli);
        $stmt->bindParam(':ostan',$ostan);
        $stmt->bindParam(':ID',$ID);
        $res = $stmt->execute();

        $stmt = null;

        if ($res) {
            echo 'true';
        }
        else {
            echo 'false';
        }

    }
    else {
        echo 'error_parameters';
    }
?>
Yazdan
  • 27
  • 6
  • You should probably start by applying proper URL encoding to the parameter values you insert into your URL there, instead of relying on that some system component will probably do it somewhere along the way. – 04FS Jan 23 '20 at 13:44
  • 1
    `my php version 5.3.5` PHP 5.3 has been [End-of-life for 5.5 years](https://www.php.net/eol.php). That means you've got tons of security holes – Machavity Jan 23 '20 at 13:46
  • @Machavity i tried php 7 but i had this problem too. – Yazdan Jan 23 '20 at 13:55
  • @04FS it worked correctly with english characters but there is problem with persian characters. – Yazdan Jan 23 '20 at 13:58
  • 1
    " i tried php 7 but i had this problem too"...that's not Machavity's point. You can fix your encoding problem in both versions in the same kind of way. But you should upgrade to the latest PHP 7 version anyway, to avoid being vulnerable to other security issues - there are problems discovered in the PHP engine which are fixed in PHP 7.x but are not fixed in 5.3. – ADyson Jan 23 '20 at 14:14
  • 2
    That might sound like a valid point to you, but it simply isn’t one. The basic Latin alphabet uses the same code points in UTF-8 and ASCII, and the letters are all “allowed” as part of a URL - so you’re likely to not run into any such problems, when the content is English only. Persian is different. – 04FS Jan 23 '20 at 14:14
  • @04FS i solved this problem by change my requests method to POST and set header to application/x-www-form-urlencoded in my volley class now i can get parameters content with persian characters both in lower 16 api android devices and higher api's thanks. – Yazdan Jan 23 '20 at 14:38

0 Answers0