如何向php发送会话电子邮件?

如何向php发送会话电子邮件?,php,android,mysql,Php,Android,Mysql,我正在开发一个应用程序,这里我想使用共享首选项来维护会话。在下面的页面中,我将提供会话,但现在我想在php文件中使用此会话电子邮件来获取当前用户的数据,如何将此会话电子邮件获取到php文件?请建议如何解决这个问题 //java file public class DetailsActivity2 extends Activity { TextView uid; TextView name1, address1, seats1, email1;

我正在开发一个应用程序,这里我想使用共享首选项来维护会话。在下面的页面中,我将提供会话,但现在我想在php文件中使用此会话电子邮件来获取当前用户的数据,如何将此会话电子邮件获取到php文件?请建议如何解决这个问题

//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);
        ?>
//java文件
公共类详细信息活动2扩展活动{
文本视图uid;
文本视图名称1、地址1、座位1、电子邮件1;
文本视图数量1;
按钮Btngetdata;
私有布尔loggedIn=false;
//获取JSON数组的URL
专用静态字符串url=”http://example.in/ticket1.php";
//JSON节点名称
私有静态最终字符串标记_USER=“result”;
私有静态最终字符串标记\u NAME=“pname”;
私有静态最终字符串标记\u AMOUNT=“pamount”;
私有静态最终字符串标记_ADDRESS=“paddress”;
私有静态最终字符串标记_SEATS=“pseats”;
JSONArray结果=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.details\u活动);
Btngetdata=(按钮)findViewById(R.id.button3\u submit);
email1=(TextView)findViewById(R.id.TextView\u email);
新建JSONParse().execute();
Btngetdata.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
SharedReferences SharedReferences=GetSharedReferences(Config.SHARED\u PREF\u NAME,Context.MODE\u PRIVATE);
loggedIn=SharedReferences.getBoolean(Config.loggedIn\u SHARED\u PREF,false);
String email=SharedReferences.getString(Config.email\u SHARED\u PREF,“不可用”);
email1.setText(电子邮件);
if(loggedIn){
意向意向=新意向(DetailsActivity2.this,LoginActivity.class);
星触觉(意向);
}
}
});
}
私有类JSONParse扩展了异步任务{
私人对话;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
//uid=(TextView)findViewById(R.id.uid);
name1=(TextView)findViewById(R.id.TextView_name1);
amount1=(TextView)findViewById(R.id.TextView\u amount1);
address1=(TextView)findViewById(R.id.TextView\u address1);
seats1=(TextView)findViewById(R.id.TextView\u sname1);
pDialog=新建进度对话框(DetailsActivity2.this);
setMessage(“获取数据…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
@凌驾
受保护的JSONObject doInBackground(字符串…args){
JSONParser jParser=新的JSONParser();
//从URL获取JSON
JSONObject json=jParser.getJSONFromUrl(url);
返回json;
}
@凌驾
受保护的void onPostExecute(JSONObject json){
pDialog.disclose();
试一试{
//获取JSON数组
result=json.getJSONArray(TAG_USER);
JSONObject c=result.getJSONObject(0);
//在变量中存储JSON项
//String id=c.getString(TAG_id);
String name=c.getString(标记名称);
字符串金额=c.getString(标记金额);
String seats=c.getString(TAG_seats);
字符串地址=c.getString(标记地址);
//在TextView中设置JSON数据
//uid.setText(id);
名称1.setText(名称);
地址1.setText(地址);
座椅1.setText(座椅);
金额1.setText(金额);
}捕获(JSONException e){
e、 printStackTrace();
}
}
}
}
//php文件

您在这里没有会话。您在哪里使用即“会话”?您发送带有“json”结果的“get”请求我向会话发送电子邮件我使用共享首选项通过电子邮件发送会话
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;
    }
}
FileUploader fileUploader = new FileUploader("http://example.in/ticket1.php","UTF-8");
fileUploader.addFormField("email","anonymous@gmail.com");
String response = fileUploader.finish();