0

Hello guys I'm developing a small web application with PHP in which I can log in and add some things to the DB, everything works fine in my localhost machine so I upload it to my hosting server which have the same dbname, dbuser, dbpassword than my localhost.. but when I hit the login button with the username and password I get this error:

Error after click login button in hosting server

and I know the hosting is up and running because when I go to the web url:

gorydev.net.ve/SistemaMatilcell

this is the code for 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;
    }
}

this is the connect.php file:

<?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();
}   
?>

the config.php file:

<?php  
return [
    'db' => [
        'hosts' => [
            'local' => 'localhost',
            'externo' => '175.99.155.194',
        ],
        'name' => 'cl55-cell',
        'user' => 'cl55-cell',
        'password' => 'matilcell12'
    ],
    'mail' => [
        'host' => 'smtp.gmail.com'
    ]
];
?>

and my Config.php class:

<?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;
    }
}
?>

and my DB in my hosting looks like this: Hosting Database

with error reporting:

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/

I repeat in my localhost pc it works fine.. same dbname same username and password

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Carlos Delgado
  • 159
  • 1
  • 2
  • 15
  • depends what's inside `connect.php` - and your path may not be correct - check for errors http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner Apr 04 '16 at 21:41
  • Please turn on error reporting (see the top answer [here](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php)) and check what error message you are getting. This will greatly help in determining what the problem is. – Chris Apr 04 '16 at 21:42
  • Please use PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html) to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). – Jay Blanchard Apr 04 '16 at 21:47
  • Hi guys thanks for reply I updated my question so you can see the rest of the files @Fred-ii- – Carlos Delgado Apr 04 '16 at 21:49
  • So I updated the code to enable error reporting and this is what I got: **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** however I do upload that **/db/connect.php/** directory to my host server – Carlos Delgado Apr 04 '16 at 21:54
  • just as I had a feeling about, the path (method) – Funk Forty Niner Apr 04 '16 at 22:47
  • below another guys posted the solution for this problem, but I'm still having an issue would you help me with that? @Fred-ii- – Carlos Delgado Apr 04 '16 at 22:56
  • Because it solve the error I was having first.. should I ask a new question with the new problem? @Fred-ii- – Carlos Delgado Apr 04 '16 at 23:36
  • it would probably be best, yes – Funk Forty Niner Apr 04 '16 at 23:44

1 Answers1

0

Looks like that you are using an absolute path and you need a relative one.

require '/db/connect.php';

should probably be

require 'db/connect.php';
gre_gor
  • 6,669
  • 9
  • 47
  • 52