gpt4 book ai didi

php - Codeigniter 项目在 hostinger 和 localhost 之间有不同的结果

转载 作者:行者123 更新时间:2023-11-30 22:22:38 25 4
gpt4 key购买 nike

我只是使用 filezilla 将我的网站从本地主机上传到托管商。我已经配置了数据库设置并且一切正常,但是如果我想登录网站,我会得到不同的结果。它给出错误“用户名或密码错误”。之后,我在我的本地主机上运行该网站。使用相同的用户名/密码登录并正常工作。我不知道错误,我在本地和托管商之间使用相同的代码

controller/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">&times;</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>

本地主机 php 版本 5.6.11

hostinger php 版本 5.6.18

最佳答案

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');

我认为此代码将为 $p 提供 0

$p = md5(mysql_real_escape_string($psw));

就用这个

$p = md5($psw);

关于php - Codeigniter 项目在 hostinger 和 localhost 之间有不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36258983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com