繁体   English   中英

使用volley和php将android连接到mysql时禁止错误403

[英]error 403 forbidden when connecting android to mysql using volley and php

我一直在将我的Android应用程序连接到我的wamp服务器,但有一天它刚刚醒来就给出了这个错误BasicNetwork.performRequest: http://192.168.43.71/database/login.php的意外响应代码403。 我确定它不是我的java代码,但是我的服务器出了问题,我对配置服务器并不是很熟悉,而且我很沮丧。 我不明白的是,有一次它正在工作,它决定不这样做。

这是我试过的 1.运行脚本使用浏览器,它工作正常2.卸载并重新安装wamp服务器,它没有工作3.将我的数据库从localhost移动到在线服务器,它没有工作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地址是动态的,它是变化的。 有时它会起作用,因为您当前的IP地址等于您的设置(192.168.43.71)。 当您启动应用程序时,应确保您设置的IP地址与当前的IP地址相同。 使用ifconfig terminal命令是可能的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM