こんにちは私はログインしてDBにいくつかのものを追加する小さなWebアプリケーションを開発しています。すべてローカルホストマシンでうまく動作します アップロードします私のホスティング同じDBNAMEを持つサーバー、DBUSER、私のlocalhost以外DBPASSWORD ..しかし、私は、ユーザー名とパスワード でのログインボタンを押したときに、私はこのエラーを取得する:PHPでホストのデータベースに接続することはできません
と私はホスティングを知っています私はウェブのURLに行くときに起動している:
gorydev.net.ve/SistemaMatilcell
これは、これはconnect.phpファイルであるlogin.php
<?php
session_start();
if(isset($_SESSION['usuario'])){
header('Location: index.php');
}
$errores = '';
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$usuario = filter_var(strtolower($_POST['usuario']), FILTER_SANITIZE_STRING);
$password = $_POST['password'];
$password = filter_var($password, FILTER_SANITIZE_STRING);
require '/db/connect.php';
$statement = $conexion->prepare('SELECT * FROM empleados WHERE usuario = :usuario AND password = :password');
$statement->execute(array(
':usuario' => $usuario,
':password' => $password
));
$resultado = $statement->fetch();
if($resultado != false){
$_SESSION['usuario'] = $usuario;
header('Location: index.php');
}else{
$errores .= '<li>Datos incorrectos.</li>';
echo $errores;
}
}
ためのコードです:
<?php
use Project\Helpers\Config;
require 'app/Config.php';
$config = new Config;
$config->load('config.php');
try {
//Datos para realizar la conexion
//$dbhost = $config->get('db.hosts.local');
$dbhost = 'localhost';
$dbname = $config->get('db.name');
$dbuser = $config->get('db.user');
$dbpass = $config->get('db.password');
$conexion = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
} catch (PDOException $e) {
echo "Error " . $e->getMessage();
}
?>
config.phpファイル:
<?php
return [
'db' => [
'hosts' => [
'local' => 'localhost',
'externo' => '175.99.155.194',
],
'name' => 'cl55-cell',
'user' => 'cl55-cell',
'password' => 'matilcell12'
],
'mail' => [
'host' => 'smtp.gmail.com'
]
];
?>
と私のConfig.phpクラス:
<?php
/*Esta clase permite cargar las configuraciones del sistema*/
namespace Project\Helpers;
class Config
{
protected $data;
protected $default = null;
public function load($file){
$this->data = require $file;
}
public function get($key, $default = null){
$this->default = $default;
$segments = explode('.', $key);
$data = $this->data;
foreach ($segments as $segment) {
if(isset($data[$segment])){
$data = $data[$segment];
}else{
$data = $this->default;
break;
}
}
return $data;
}
public function exists($key){
return $this->get($key) !== $this->default;
}
}
?>
と私のホスティングの私のDBは次のようになります。エラー報告と
:
私は私のローカルホストのPCに繰り返しWarning: require(/db/connect.php): failed to open stream: No such file or directory in /home/sites/gorydev.net.ve/public_html/SistemaMatilcell/login.php on line 17 Fatal error: require(): Failed opening required '/db/connect.php' (include_path='.:/usr/share/pear55:/usr/share/php') in /home/sites/gorydev.net.ve/public_html/SistemaMatilcell/login.php on line 17 /db/connect.php/
それは罰金...同じdbnameに同じユーザ名とパスワード
作品
が内側 'connect.php'何によって決まるべきである - そして、あなたのパスが正しくない可能性があります - http://php.net/manual/en/functionエラーをチェック。 error-reporting.php –
エラー報告をオンにしてください(トップの回答[here](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php)を参照してください)。取得しているエラーメッセージを確認してください。これは、問題が何であるかを判断するのに大いに役立ちます。 – Chris
パスワードのセキュリティを処理するには、PHPの[組み込み関数](http://jayblanchard.net/proper_password_hashing_with_PHP.html)を使用してください。 5.5より小さいPHPバージョンを使用している場合、 'password_hash()' [互換パック](https://github.com/ircmaxell/password_compat)を使用することができます。 –