Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在调用5秒后使http请求过期_Php_Android - Fatal编程技术网

Php 在调用5秒后使http请求过期

Php 在调用5秒后使http请求过期,php,android,Php,Android,我想让http请求在android中5秒后过期。我正在使用php mysql框架,并使用下面的代码显示用户的图像、艺术家。 下面的代码工作正常,但不安全。如何保护它?请告诉我怎样才能做到这一点 提前谢谢 public class CustomizedListView extends Activity { // All static variables static final String URL = "http://example.com/getmsgs/strno=123";

我想让http请求在android中5秒后过期。我正在使用php mysql框架,并使用下面的代码显示用户的图像、艺术家。 下面的代码工作正常,但不安全。如何保护它?请告诉我怎样才能做到这一点

提前谢谢

public class CustomizedListView extends Activity {
    // All static variables
    static final String URL = "http://example.com/getmsgs/strno=123";
    // XML node keys
    static final String KEY_SONG = "song"; // parent node
    static final String KEY_ID = "id";
    static final String KEY_TITLE = "title";
    static final String KEY_ARTIST = "artist";
    static final String KEY_DURATION = "duration";
    static final String KEY_THUMB_URL = "thumb_url";

    ListView list;
    LazyAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

        JSONObject json = JSONfunctions.getJSONfromURL(URL);


        try {
            JSONObject arr2 = json.getJSONObject("feed");
            JSONArray arr = arr2.getJSONArray("entry");

            for (int i = 0; i < arr.length(); i++) {
                JSONObject e1 = arr.getJSONObject(i);

                JSONArray arr3 = e1.getJSONArray("im:image");

                JSONObject arr8 = e1.getJSONObject("im:name");

                JSONObject arr10 = e1.getJSONObject("im:artist");

                    JSONObject e12 = arr3.getJSONObject(0);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            map.put(KEY_THUMB_URL,  e12.getString("label"));

            map.put(KEY_ARTIST, arr8.getString("label"));
            map.put(KEY_TITLE, arr10.getString("label"));
            // adding HashList to ArrayList
            songsList.add(map);
            }

        } catch (JSONException e) {
            // Log.e("log_tag", "Error parsing data "+e.toString());
            Toast.makeText(getBaseContext(),
                    "Network communication error!", 5).show();
        }


        list=(ListView)findViewById(R.id.list);

        // Getting adapter by passing xml data ArrayList
        adapter=new LazyAdapter(this, songsList);        
        list.setAdapter(adapter);

        // Click event for single list row
        list.setOnItemClickListener(new OnItemClickListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {


                HashMap<String, String> o = (HashMap<String, String>) list.getItemAtPosition(position);
                Toast.makeText(CustomizedListView.this, "ID '" + o.get("KEY_TITLE") + "' was clicked.", Toast.LENGTH_SHORT).show(); 

            }
        });     
    }   
}
public类CustomizedListView扩展活动{
//所有静态变量
静态最终字符串URL=”http://example.com/getmsgs/strno=123";
//XML节点密钥
静态最终字符串键\u SONG=“SONG”//父节点
静态最终字符串键\u ID=“ID”;
静态最终字符串键\u TITLE=“TITLE”;
静态最终字符串键\u ARTIST=“ARTIST”;
静态最终字符串键\u DURATION=“DURATION”;
静态最终字符串键\u THUMB\u URL=“THUMB\u URL”;
列表视图列表;
懒散适配器;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList songsList=新的ArrayList();
JSONObject json=JSONfunctions.getJSONfromURL(URL);
试一试{
JSONObject arr2=json.getJSONObject(“提要”);
JSONArray arr=arr2.getJSONArray(“条目”);
对于(int i=0;i
上面请求的PHP代码

    <?php

    $strno=$_GET['strno'];

    if (isset($strno))
    {
            $connect=mysql_connect("localhost","test","test") or die ('Connection error!!!');
            mysql_select_db("test") or die ('Database error!!!');

        $query=mysql_query("select sno FROM users  where strno='$strno';");
        while($row = mysql_fetch_assoc($query))

        {
            $jsonoutput='{"json":{
                "image":"'.$row['image'].'",
"artist":"'.$row['artist'].'",
"name":"'.$row['name'].'"
                }}';
        }

    }

    echo trim($jsonoutput);
    mysql_close($connect) or die ('Unable to close connection-error!!!');
    }

    ?>

和?运行时会发生什么?方法的代码是什么?这就是你应该修复它的地方。它执行得很好,但我想通过加密一些东西来保护整个请求,这样就没有人可以再次使用该链接。因此保护该请求。@Axarydax该代码工作得很好。我如何保护它,使它在5秒后不能再使用,或者通过在浏览器中复制该链接来保护它。