嗨,我对此感到厌烦和厌倦,无法在网上找到任何解决方案,所以这是我的问题。我正在使用 Apache HTTP 帖子登录网站。提供我的凭据。但是无论我从网络上使用什么代码片段,无论我做什么,它总是会再次返回我的登录页面作为响应。这是我的代码,请提供解决方案。
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", "xxx"));
nameValuePairs.add(new BasicNameValuePair("password", "xxx"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.i("Response num:", "" + response.getStatusLine().toString());
Log.i("response page:", "" + responseHandler(response));
Log.i("Headers:", "" + response.getHeaders("Location").toString());
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
php脚本是:
<?php
session_start();
include('Connectdb.php');
$result = mysql_query("SELECT * FROM user_accounts where username ='".$_POST["username"]."' AND password ='".$_POST["password"]."'");
if($row = mysql_fetch_array($result))
{
$_SESSION['Suserid']=$row['hospital_id'];
// mysql_close($con);
if ($row['acc_type']=="patient"){
$_SESSION['verifiedUserType']="patient";
header('Location:./home_P.php');
}
else
if ($row['acc_type']=="admin"){
$_SESSION['verifiedUserType']="admin";
header('Location:./home_admin.php');}
else
if ($row['acc_type']=="doctor"){
$_SESSION['verifiedUserType']="doctor";
header('Location:./home_doc.php');}
exit;
}
else
{
mysql_close($con);
//session_start();
header('Location:./index.php?failed=1');
}
?>
如何在登录后获取页面并在用户登录后通过获取 cookie 来维护会话?ps 即使我输入错误的用户名或密码,我也会得到 http 1.1 200 OK 状态。