how do i give session email to php?

rohiH

I am developing an app, here i want to maintain the session using shared preferences.In this following page I'm giving session but now i want to use this session email in php file to fetch data of current user, how do i get this session email to php file? Please suggest how to solve this.

//java file

public class DetailsActivity2 extends Activity {
            TextView uid;
            TextView name1, address1, seats1, email1;
            TextView amount1;
            Button Btngetdata;
            private boolean loggedIn = false;

            //URL to get JSON Array
         private static String url = "http://example.in/ticket1.php";

            //JSON Node Names
            private static final String TAG_USER = "result";
            private static final String TAG_NAME = "pname";
            private static final String TAG_AMOUNT = "pamount";
            private static final String TAG_ADDRESS = "paddress";
            private static final String TAG_SEATS = "pseats";

            JSONArray result = null;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                setContentView(R.layout.details_activity);
                Btngetdata = (Button)findViewById(R.id.button3_submit);
                email1=(TextView)findViewById(R.id.textView_email);

                new JSONParse().execute();

                Btngetdata.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
                        loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF, false);
                        String email = sharedPreferences.getString(Config.EMAIL_SHARED_PREF, "Not Available");
                        email1.setText(email);

                        if(loggedIn){

                            Intent intent = new Intent(DetailsActivity2.this, LoginActivity.class);
                            startActivity(intent);
                        }
                    }
                });
            }

            private class JSONParse extends AsyncTask<String, String, JSONObject> {
                private ProgressDialog pDialog;
                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                //    uid = (TextView)findViewById(R.id.uid);
                    name1 = (TextView)findViewById(R.id.textView_name1);
                    amount1 = (TextView)findViewById(R.id.textView_amount1);
                    address1= (TextView)findViewById(R.id.textView_address1);
                    seats1= (TextView)findViewById(R.id.textView_sname1);

                    pDialog = new ProgressDialog(DetailsActivity2.this);
                    pDialog.setMessage("Getting Data ...");
                    pDialog.setIndeterminate(false);
                    pDialog.setCancelable(true);
                    pDialog.show();

                }

                @Override
                protected JSONObject doInBackground(String... args) {
                    JSONParser jParser = new JSONParser();

                    // Getting JSON from URL
                    JSONObject json = jParser.getJSONFromUrl(url);
                    return json;
                }
                @Override
                protected void onPostExecute(JSONObject json) {
                    pDialog.dismiss();
                    try {
                        // Getting JSON Array
                        result = json.getJSONArray(TAG_USER);
                        JSONObject c = result.getJSONObject(0);

                        // Storing  JSON item in a Variable
                     //   String id = c.getString(TAG_ID);
                        String name = c.getString(TAG_NAME);
                        String amount = c.getString(TAG_AMOUNT);
                        String seats = c.getString(TAG_SEATS);
                        String address = c.getString(TAG_ADDRESS);



                        //Set JSON Data in TextView
                      //  uid.setText(id);
                        name1.setText(name);
                        address1.setText(address);
                        seats1.setText(seats);
                        amount1.setText(amount);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

//php file        
        <?php

        $id= $_GET['email'];
        $sql = "SELECT * FROM tbl_users WHERE email='$id'";

        $con=mysqli_connect("localhost","user","pass","db");

        $r =mysqli_query($con,$sql);
        $result =array();

        while($row =mysqli_fetch_array($r)){
            array_push($result,array(
                'pname'=>$row['pname'],
                'paddress'=>$row['paddress'],
                'pseats'=>$row['pseats'],
                'pamount'=>$row['pamount']
            ));
        }

        echo json_encode(array('result'=>$result));
        mysqli_close($con);
        ?>
Sabish.M
public class FileUploader {
    private static final String LINE_FEED = "\r\n";
    private final String boundary;
    private HttpsURLConnection httpConn;
    private String charset;
    private OutputStream outputStream;
    private PrintWriter writer;

    public FileUploader(String requestURL, String charset)
            throws IOException {
        this.charset = charset;

        // creates a unique boundary based on time stamp
        boundary = "===" + System.currentTimeMillis() + "===";

        URL url = new URL(requestURL);
        httpConn = (HttpsURLConnection) url.openConnection();
        httpConn.setUseCaches(false);
        httpConn.setDoOutput(true); // indicates POST method
        httpConn.setDoInput(true);
        httpConn.setRequestMethod("POST");
        httpConn.setRequestProperty("Content-Type",
                "multipart/form-data; boundary=" + boundary);

        httpConn.setRequestProperty("User-Agent", "CodeJava Agent");
        outputStream = httpConn.getOutputStream();
        writer = new PrintWriter(new OutputStreamWriter(outputStream, charset),
                true);
    }

    /**
     * Adds a form field to the request
     *
     * @param name  field name
     * @param value field value
     */
    public void addFormField(String name, String value) {
        writer.append("--").append(boundary).append(LINE_FEED);
        writer.append("Content-Disposition: form-data; name=\"").append(name).append("\"")
                .append(LINE_FEED);
        writer.append("Content-Type: text/plain; charset=").append(charset).append(
                LINE_FEED);
        writer.append(LINE_FEED);
        writer.append(value).append(LINE_FEED);
        writer.flush();
    }

    /**
     * Adds a upload file section to the request
     *
     * @param fieldName  name attribute in <input type="file" name="..." />
     * @param uploadFile a File to be uploaded
     * @throws IOException
     */
    public void addFilePart(String fieldName, File uploadFile)
            throws IOException {
        String fileName = uploadFile.getName();
        writer.append("--").append(boundary).append(LINE_FEED);
        writer.append("Content-Disposition: form-data; name=\"").append(fieldName).append("\"; filename=\"").append(fileName).append("\"")
                .append(LINE_FEED);
        writer.append("Content-Type: ").append(URLConnection.guessContentTypeFromName(fileName))
                .append(LINE_FEED);
        writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
        writer.append(LINE_FEED);
        writer.flush();

        FileInputStream inputStream = new FileInputStream(uploadFile);
        byte[] buffer = new byte[4096];
        int bytesRead = -1;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, bytesRead);
        }
        outputStream.flush();
        inputStream.close();

        writer.append(LINE_FEED);
        writer.flush();
    }

    /**
     * Adds a header field to the request.
     *
     * @param name  - name of the header field
     * @param value - value of the header field
     */
    public void addHeaderField(String name, String value) {
        writer.append(name).append(": ").append(value).append(LINE_FEED);
        writer.flush();
    }

    /**
     * Completes the request and receives response from the server.
     *
     * @return a list of Strings as response in case the server returned
     * status OK, otherwise an exception is thrown.
     * @throws IOException
     */
    public String finish() {
        String response = "";

        writer.append(LINE_FEED).flush();
        writer.append("--").append(boundary).append("--").append(LINE_FEED);
        writer.close();

        // checks server's status code first
        int status = 0;
        try {
            status = httpConn.getResponseCode();

            if (status == HttpsURLConnection.HTTP_OK) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        httpConn.getInputStream()));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    response += line;
                }
                reader.close();
                httpConn.disconnect();
            } else {
                return null;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

        return response;
    }
}

Then

FileUploader fileUploader = new FileUploader("http://example.in/ticket1.php","UTF-8");
fileUploader.addFormField("email","[email protected]");
String response = fileUploader.finish();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I expire a PHP session after 30 minutes?

From Dev

How do I stop cURL from deadlocking my PHP session?

From Dev

How do I destroy a specific session variable in PHP?

From Dev

How do I stop cURL from deadlocking my PHP session?

From Dev

How do I hold a session through a PHP login redirect?

From Dev

How do I use a PHP session to prevent duplicate form submissions?

From Dev

On a Mac Sierra, how can I give an ssh session access to the display?

From Dev

How do I give a argument to a XSL Transformation?

From Dev

how do I give users capabilities

From Dev

How do I give inputs through NSURL

From Dev

How do i give an editText a fixed width

From Dev

In plesk how do I give the user the privileges to create databases using php, but in his domain only

From Dev

How to email $_SESSION variables

From Dev

Do I need to use session_start() in PHP to use $_SESSION?

From Dev

how to give empty for email in json

From Dev

How do i save raw php code to database or text file for sending email message?

From Dev

How do I run this regex in PHP that parse full email address with name?

From Dev

How do I connect to the database, shoot and email and update database simultaneously when the user clicks the submit button in PHP?

From Dev

How do I change the "from email address" associated with PHP contact form

From Dev

How do I restrict special characters except underscore, hyphen and dot in email field in PHP?

From Dev

How do I send all values created by jquery uploader of php form variables by email

From Dev

How do I record the email address of a user that clicks a link in an email?

From Dev

How do I send Email using an email client?

From Dev

How do I send files in an email by using the Python email module?

From Dev

how do i send an email through joomla

From Dev

How do I customize the Mailboxer email Subject?

From Dev

How do I assert the result is an email in PHPUnit?

From Dev

How do I send the email object to a function?

From Dev

how do i send an email through joomla

Related Related

  1. 1

    How do I expire a PHP session after 30 minutes?

  2. 2

    How do I stop cURL from deadlocking my PHP session?

  3. 3

    How do I destroy a specific session variable in PHP?

  4. 4

    How do I stop cURL from deadlocking my PHP session?

  5. 5

    How do I hold a session through a PHP login redirect?

  6. 6

    How do I use a PHP session to prevent duplicate form submissions?

  7. 7

    On a Mac Sierra, how can I give an ssh session access to the display?

  8. 8

    How do I give a argument to a XSL Transformation?

  9. 9

    how do I give users capabilities

  10. 10

    How do I give inputs through NSURL

  11. 11

    How do i give an editText a fixed width

  12. 12

    In plesk how do I give the user the privileges to create databases using php, but in his domain only

  13. 13

    How to email $_SESSION variables

  14. 14

    Do I need to use session_start() in PHP to use $_SESSION?

  15. 15

    how to give empty for email in json

  16. 16

    How do i save raw php code to database or text file for sending email message?

  17. 17

    How do I run this regex in PHP that parse full email address with name?

  18. 18

    How do I connect to the database, shoot and email and update database simultaneously when the user clicks the submit button in PHP?

  19. 19

    How do I change the "from email address" associated with PHP contact form

  20. 20

    How do I restrict special characters except underscore, hyphen and dot in email field in PHP?

  21. 21

    How do I send all values created by jquery uploader of php form variables by email

  22. 22

    How do I record the email address of a user that clicks a link in an email?

  23. 23

    How do I send Email using an email client?

  24. 24

    How do I send files in an email by using the Python email module?

  25. 25

    how do i send an email through joomla

  26. 26

    How do I customize the Mailboxer email Subject?

  27. 27

    How do I assert the result is an email in PHPUnit?

  28. 28

    How do I send the email object to a function?

  29. 29

    how do i send an email through joomla

HotTag

Archive