我一直在将我的android应用程序连接到我的wamp服务器,但有一天它刚醒来时发出此错误BasicNetwork.performRequest:对于http://192.168.43.71/database/login.php意外的响应代码403。我确定它不是我的java代码,但是我的服务器出了问题,我对配置服务器不是很熟悉,而且我沮丧地溺水了。我不明白的是有一次它工作,它只是决定不去。当使用volley和php连接android到mysql时,出现错误403禁止
这就是我想 1.使用浏览器中运行的脚本,它工作正常 2.卸载并重新安装WAMP的服务器,并没有从本地主机工作 3.移动我的数据库到在线服务器它没有工作 3.我意识到,只有PHP脚本中,我必须发布参数给出了这个错误,在我只需要从服务器检索数据的情况下,它不工作的参数
以下是我的登录脚本和我的数据库连接。我相信数据库连接工作正常
<?php
$response = array();
$array = array();
$details = array();
// check for required fields
if (!empty($_POST)) {
$phone_number = $_POST['user_phone_number'];
$password = md5($_POST['user_password']);
include 'database.php';
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql2 = "SELECT * FROM users WHERE user_phone_number OR user_email = ? AND user_password = ?";
$result2 = $pdo->prepare($sql2);
$result2->execute(array($phone_number,$password));
while ($row = $result2->fetch(PDO::FETCH_ASSOC)){
$array["user_phone"] = $row["user_phone"];
$array["user_id"] = $row["user_id"];
$array["user_imei"] = $row["user_imei"];
$array["user_name"] = $row["user_name"];
$array["user_surname"] = $row["user_surname"];
$array["user_phone_number"] = $row["user_phone_number"];
$array["user_email"] = $row["user_email"];
$array["user_password"] = $row["user_password"];
}
if($result2){
if($array == null){
$array["user_phone"] = "error";
$array["message"] = "Wrong phone number or password";
$json = json_encode($array);
echo $json;
}else{
$json = json_encode($array);
echo $json;
}
}
} else {
$array["user_phone"] = "0";
$array["message"] = "Required field(s) is missing";
echo json_encode($array);
}
Database::disconnect();
?>
数据库连接
<?php
class Database{
private static $dbName = 'testdb';
private static $dbHost = 'localhost';
private static $dbUsername = 'root';
private static $dbPassword = '';
private static $cont = null;
public function __construct() {
die('Init not allowed');
}
public static function connect(){
//Open connection through the who;e application
if(null == self::$cont){
try {
self::$cont = new PDO("mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbPassword);
} catch (PDOException $ex) {
die($ex->getMessage());
}
}
return self::$cont;
}
public static function disconnect(){
self::$cont == null;
}
}
?>
在我运行应用程序之前,ip地址是我检查的第一件事。我很确定它的正确性 – 2015-02-24 07:57:31