我使用的是EllisLab的应用程序框架。我有登录问题。$ _POST方法没有在表单提交上存储数据。我在表单提交时收到以下错误。请注意,var_dump($ POST)返回array(0){}
以下是登录页面代码
<html>
<head>
<title> Control Panel</title>
</head>
<body>
<form action = "<?php echo base_url();?>admin/login" method = "POST">
<table>
<tr>
<td> Username : </td>
<td> <input type = "text" name = "username" id = "usr"/> </td>
</tr>
<tr>
<td> Password : </td>
<td> <input type = "password" name = "password" id = "pass"/> </td>
</tr>
<tr>
<td></td>
<td> <input type = "submit" name = "submit" value = "Login"/> </td>
</tr>
</table>
</form>
</body>
</html>
&#13;
以下是admin_model.php代码。
<?php
class Admin_model extends CI_Model{
public function __construct(){
parent :: __construct();
}
function loginchk(){
var_dump($_POST);
$usr = $_POST['username'];
$pass = $_POST['password'];
$pass1 = md5($pass); // *****@key***
$res = $this->db->get_where('tbl_user', array('clm_userid'=>$usr, 'clm_password'=>$pass1));
if($res->num_rows()==0 && $usr == "admin" && $pass == "admin"){
$res=1;
}else if($res->num_rows()>=1){
$res =1;
}else{
$res = 0;
}
return $res;
}
function getusers()
{
$query = $this->db->query("select * from tbl_device");
return $query->result_array();
}
function getsingledevice($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_device where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number'");
return $query->result_array();
}
function getcalllog($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_calllogs where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number' ");
return $query->result_array();
}
function getsmslog($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_smslogs where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number' ");
return $query->result_array();
}
function getbrowserlog($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_browserlogs where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number' ");
return $query->result_array();
}
function getgpslog($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_gps where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number' ");
return $query->result_array();
}
function getpackages($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_packages where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number' ");
return $query->result_array();
}
function getdevice($id=false, $name=false, $number=false)
{
$query = $this->db->query("select * from tbl_history where clm_device_id = '$id' and clm_device_name ='$name' and clm_device_number = '$number'");
return $query->result_array();
}
function addhistory($id=false, $command = false){
$data = array('clm_device_id' => $id, 'clm_commandhistory' => $command);
$data_device = array('clm_commandseen'=>'0', 'clm_currentcommand'=> $command);
if($id == "all"){
$this->db->update('tbl_device', $data_device);
}else{
$this->db->where('clm_device_id', $id);
$this->db->update('tbl_device', $data_device);
}
$this->db->insert('tbl_history', $data);
return;
}
function unreg($id){
if($id=="all"){
$this->db->query("delete from tbl_device");
$this->db->query("delete from tbl_history");
$this->db->query("delete from tbl_browserlogs");
$this->db->query("delete from tbl_calllogs");
$this->db->query("delete from tbl_gps");
$this->db->query("delete from tbl_packages");
$this->db->query("delete from tbl_smslogs");
return;
}else{
$this->db->query("delete from tbl_device where clm_device_id = '$id'");
$this->db->query("delete from tbl_history where clm_device_id = '$id'");
$this->db->query("delete from tbl_browserlogs where clm_device_id = '$id'");
$this->db->query("delete from tbl_calllogs where clm_device_id = '$id'");
$this->db->query("delete from tbl_gps where clm_device_id = '$id'");
$this->db->query("delete from tbl_packages where clm_device_id = '$id'");
$this->db->query("delete from tbl_smslogs where clm_device_id = '$id'");
return;
}
}
function addcmd($data){
return $this->db->insert('tbl_cmd',$data);
}
function getcmd($id=false){
if($id==false){
return $this->db->get('tbl_cmd')->result_array();
}else{
return $this->db->get_where('tbl_cmd', array('clm_id'=> $id))->row_array();
}
}
function updatecmd($id=false,$arr=false){
$data['clm_cmdname'] = $arr[0];
$data['clm_cmdvalue'] = $arr[1];
$this->db->where('clm_id', $id);
return $this->db->update('tbl_cmd',$data);
}
function deletecmd($id=false){
return $this->db->query("delete from tbl_cmd where clm_id='$id'");
}
}
?>
&#13;
以下是admin.php控制器代码:
<?php
class Admin extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
$this->output->set_header('Pragma: no-cache');
$this->load->model('admin_model');
$this->load->helper('url');
}
function index(){
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
redirect('admin/home');
}
}
else{
$this->load->view('admin/login');
}
}
function login(){
$res = $this->admin_model->loginchk();
if($res == 1){
$data = array(
'user' => $_POST['username'],
'type' => 'admin',
'logged_in' => TRUE
);
$this->session->set_userdata($data);
$userdata['users'] = $this->admin_model->getusers();
$userdata['cmd'] = $this->admin_model->getcmd();
$this->load->view('admin/header_admin');
$this->load->view('admin/home',$userdata);
}
else{
$this->load->view('admin/login');
}
}
function logout()
{
$this->session->unset_userdata('user');
$this->session->unset_userdata('logged_in');
$this->session->unset_userdata('type');
$this->session->sess_destroy();
redirect('admin');
}
function home()
{
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
$userdata['users'] = $this->admin_model->getusers();
$userdata['cmd'] = $this->admin_model->getcmd();
$this->load->view('admin/header_admin');
$this->load->view('admin/home',$userdata);
}
}
else{
$this->load->view('admin/login');
}
//$today = date("Y-m-d");
//echo $today;
}
function viewdevice($id=false, $name=false, $number=false)
{
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
$userdata['users'] = $this->admin_model->getdevice($id,$name,$number);
$userdata['users1'] = $this->admin_model->getsingledevice($id,$name,$number);
$userdata['deviceid'] = $id;
$userdata['devicename'] = $name;
$userdata['devicenumber'] = $number;
$userdata['cmd'] = $this->admin_model->getcmd();
$userdata['calllog'] = $this->admin_model->getcalllog($id,$name,$number);
$userdata['smslog'] = $this->admin_model->getsmslog($id,$name,$number);
$userdata['browserlog'] = $this->admin_model->getbrowserlog($id,$name,$number);
$userdata['gpslog'] = $this->admin_model->getgpslog($id,$name,$number);
$userdata['packages'] = $this->admin_model->getpackages($id);
$this->load->view('admin/header_admin');
$this->load->view('admin/device',$userdata);
}
}
else{
$this->load->view('admin/login');
}
}
function addcommand($id=false, $name=false, $number=false)
{
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
$com = $_POST['command'];
//echo $com . "<br>";
$this->admin_model->addhistory($id,$com);
$userdata['users'] = $this->admin_model->getdevice($id,$name,$number);
$userdata['users1'] = $this->admin_model->getsingledevice($id,$name,$number);
$userdata['deviceid'] = $id;
$userdata['devicename'] = $name;
$userdata['devicenumber'] = $number;
$userdata['cmd'] = $this->admin_model->getcmd();
$userdata['calllog'] = $this->admin_model->getcalllog($id,$name,$number);
$userdata['smslog'] = $this->admin_model->getsmslog($id,$name,$number);
$userdata['browserlog'] = $this->admin_model->getbrowserlog($id,$name,$number);
$userdata['gpslog'] = $this->admin_model->getgpslog($id,$name,$number);
$userdata['packages'] = $this->admin_model->getpackages($id);
$this->load->view('admin/header_admin');
$this->load->view('admin/device',$userdata);
}
}
else{
$this->load->view('admin/login');
}
}
function updatecontent($todo=false)
{
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
if($todo == "sendcmd"){
$trimmed = trim($GLOBALS["HTTP_RAW_POST_DATA"], '[]');
$prevarr = explode(",", $trimmed); /// Stores cmd and ids
$arr = explode("'*'", $prevarr[0]);
$arr = str_replace('"', '', $arr); /// IDs
$cmd = str_replace('"', '', $prevarr[1]); // cmd
$ct = 0;
foreach ($arr as $ids) {
$this->admin_model->addhistory($ids,$cmd);
$ct++;
}
}else{
$trimmed = trim($GLOBALS["HTTP_RAW_POST_DATA"], '[]');
$arr = explode("'*'", $trimmed);
$arr = str_replace('"', '', $arr);
//print_r($arr);
foreach ($arr as $ids) {
$this->admin_model->unreg($ids);
}
}
}
$userdata['users'] = $this->admin_model->getusers();
$userdata['cmd'] = $this->admin_model->getcmd();
$this->load->view('admin/home',$userdata);
}
}
else{
$this->load->view('admin/login');
}
}
function help()
{
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
$this->load->view('admin/header_admin');
$this->load->view('admin/help');
}
}
else{
$this->load->view('admin/login');
}
//$today = date("Y-m-d");
//echo $today;
}
function chat()
{
if ($this->session->userdata('logged_in') == TRUE)
{
if($this->session->userdata('type') == 'admin') {
$this->load->view('admin/header_admin');
if(isset($_POST['msg'])){
$message = $_POST['msg'];
$user = "admin";
$ip = $_SERVER['REMOTE_ADDR'];
$datum = date("[d-m - H:i]");
$final = $datum . "<br />" . $message . "<br /><br />";
$verbindung = mysql_connect("alexandroid.db.9664540.hostedresource.com", "alexandroid" , "Bifro7!23")
or die("Verbindung zur Datenbank konnte nicht hergestellt werden.");
mysql_select_db("alexandroid") or die ("Datenbank konnte nicht ausgewählt werden");
$eintrag = "INSERT INTO chat_messages (chat_messages_id, user, message, ip, date) VALUES ('', '$user', '$message', '$ip', '$datum')";
$eintragen = mysql_query($eintrag);
}
$this->load->view('admin/chat');
}
}
else{
$this->load->view('admin/login');
}
}
function addcmd(){
if(isset($_POST['clm_cmdname'])){
//print_r($_POST);
$this->admin_model->addcmd($_POST);
}
//print_r($this->admin_model->getcmd());
$this->load->view('admin/header_admin');
$this->load->view('admin/addcmd');
}
function viewcmd($id=false){
$data['cmd'] = $this->admin_model->getcmd();
$data['id'] = 0;
$this->load->view('admin/header_admin');
$this->load->view('admin/editcmd', $data);
}
function editcmd($id=false){
echo $id;
$data['cmd'] = $this->admin_model->getcmd();
//print_r($data['cmd']);
$data['id'] = $id;
$this->load->view('admin/editcmd', $data);
}
function updatecmd($id=false){
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$trimmed = trim($GLOBALS["HTTP_RAW_POST_DATA"], '[]');
$arr = explode(",", $trimmed);
$arr = str_replace('"', '', $arr);
$this->admin_model->updatecmd($id,$arr);
//print_r($arr);
}
$data['cmd'] = $this->admin_model->getcmd();
$data['id'] = 0;
$this->load->view('admin/editcmd', $data);
}
function deletecmd($id = false){
$this->admin_model->deletecmd($id);
$data['cmd'] = $this->admin_model->getcmd();
$data['id'] = 0;
$this->load->view('admin/editcmd', $data);
}
}
?>
&#13;
答案 0 :(得分:0)
您正在管理控制器或文件中调用登录功能,因此$ _POST值保存控制器内的数据,并且您在MODEL中使用$ _POST是不可能的。你必须在你的控制器中使用$ _POST,而不是像@Kanishka Panamaldeniya那样将变量传递给你的模型。
答案 1 :(得分:0)
我调试了很多帖子。相信我,它将由浏览器发送到您的脚本。如果您不确定,出了什么问题,请运行浏览器调试器(F11或Ctrl + Shift + I),以查看您的请求真正发送到您的脚本的内容。另外,如上所述,$_POST
是register_global
,因此无论您来自何处或已经包含了多少个文件,它都会在每个php文件中设置。也许你的框架得到了你需要的所有参数的请求对象?请先看一下......