我只是将我的网站从localhost上传到带有filezilla的hostinger。 我已经配置了数据库设置并且运行良好,但如果我想登录网站,我会得到不同的结果。它会给出错误"用户名或密码错误"。 之后,我在localhost中运行该网站。使用相同的用户名/密码登录并运行。 我不知道错误,我在本地和hostinger之间使用相同的代码
控制器/ login.php中
<?php
class Login extends CI_Controller {
function __construct() {
parent::__construct();
session_start();
$this->load->model(array('mlogin'));
if ($this->session->userdata('email')) {
$this->load->view('header1');
}
elseif (!$this->session->userdata('email')) {
$this->load->view('header');
}
}
function index() {
$this->load->view('login');
}
function proses() {
$this->form_validation->set_rules('email', 'email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'password', 'required|trim|xss_clean');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
} else {
$usr = $this->input->post('email');
$psw = $this->input->post('password');
$u = mysql_real_escape_string($usr);
$p = md5(mysql_real_escape_string($psw));
$cek = $this->mlogin->cek($u, $p);
if ($cek->num_rows() > 0) {
//login berhasil, buat session
foreach ($cek->result() as $qad) {
$sess_data['u_id'] = $qad->u_id;
$sess_data['nama'] = $qad->nama;
$sess_data['email'] = $qad->email;
$sess_data['role'] = $qad->role;
$this->session->set_userdata($sess_data);
}
redirect('home');
} else {
$this->session->set_flashdata('result_login', '<br>Username atau Password yang anda masukkan salah.');
redirect('login');
}
}
}
function logout() {
$this->session->sess_destroy();
redirect('login');
}}
模型/ mlogin.php
<?php
class Mlogin extends CI_Model {
private $table = "user";
function cek($email, $password) {
$this->db->where("email", $email);
$this->db->where("u_paswd", $password);
return $this->db->get("user");
}
function semua() {
return $this->db->get("user");
}
function cekKode($kode) {
$this->db->where("email", $kode);
return $this->db->get("user");
}
function cekId($kode) {
$this->db->where("u_id", $kode);
return $this->db->get("user");
}
function getLoginData($usr, $psw) {
$u = mysql_real_escape_string($usr);
$p = md5(mysql_real_escape_string($psw));
$q_cek_login = $this->db->get_where('users', array('email' => $u, 'password' => $p));
if (count($q_cek_login->result()) > 0) {
foreach ($q_cek_login->result() as $qck) {
foreach ($q_cek_login->result() as $qad) {
$sess_data['logged_in'] = 'vera';
$sess_data['u_id'] = $qad->u_id;
$sess_data['email'] = $qad->email;
$sess_data['nama'] = $qad->nama;
$sess_data['group'] = $qad->group;
$sess_data['rid'] = $qad->rid;
$this->session->set_userdata($sess_data);
}
redirect('main');
}
} else {
$this->session->set_flashdata('result_login', '<br>Username atau Password yang anda masukkan salah.');
header('location:' . base_url() . 'login');
}
}
function update($id, $info) {
$this->db->where("u_id", $id);
$this->db->update("user", $info);
}
function simpan($info) {
$this->db->insert("user", $info);
}
function hapus($kode) {
$this->db->where("u_id", $kode);
$this->db->delete("user");
}
}
查看/ login.php中
<html>
<head>
<meta charset="UTF-8">
<title>Log in</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- Font Awesome Icons -->
<link href="<?php echo base_url('assets/css/font-awesome.min.css'); ?>" rel="stylesheet">
<!-- Theme style -->
<link href="<?php echo base_url('assets/css/AdminLTE.min.css'); ?>" rel="stylesheet">
<!-- iCheck -->
<link href="<?php echo base_url('assets/js/plugins/iCheck/square/blue.css'); ?>" rel="stylesheet">
</head>
<body>
<body class="login-page">
<div class="login-box">
<div class="login-logo">
<div class="login-box-body">
<h2>Login</h2>
<form action="<?php echo site_url('login/proses'); ?>" method="post">
<?php
if (validation_errors() || $this->session->flashdata('result_login')) {
?>
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong>
<?php echo validation_errors(); ?>
<?php echo $this->session->flashdata('result_login'); ?>
</div>
<?php } ?>
<div class="form-group has-feedback">
<input type="email" name="email" class="form-control" placeholder="Username"/>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="Password"/>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div>
<button type="submit" class="btn btn-primary btn-block btn-flat">Masuk</button>
<br>
<a href="<?php echo base_url();?>index.php/user"><h4>Daftar Anggota Baru</h4></a>
</div><!-- /.col -->
</div>
</form>
</div><!-- /.login-box-body -->
</div><!-- /.login-box -->
<!-- jQuery 2.1.3 -->
<script src="<?php echo base_url('assets/js/plugins/jQuery/jQuery-2.1.3.min.js'); ?>"></script>
<!-- Bootstrap 3.3.2 JS -->
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
<!-- iCheck -->
<script src="<?php echo base_url('assets/js/plugins/iCheck/icheck.min.js'); ?>"></script>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
</script>
<script>
$(function () {
$("#slider").responsiveSlides({
auto: true,
nav: true,
speed: 500,
namespace: "callbacks",
pager: true,
});
});
</script>
<!--footer-starts-->
<?php $this->load->view('footer') ?>
<!---->
</div>
</body>
</html>
localhost php version 5.6.11
hostinger php version 5.6.18
答案 0 :(得分:0)
Hostinger对大写敏感
更改此代码
$this->form_validation->set_rules('email', 'email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'password', 'required|trim|xss_clean');
用这个
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
我觉得这段代码会给你0美元
$p = md5(mysql_real_escape_string($psw));
只需使用此
$p = md5($psw);