首页 文章

CodeIgniter:以登录表单丢失我的POST变量

提问于
浏览
0

我有一个登录表单作为CodeIgniter中的视图:

<?php 

            echo '$_POST<hr>';
            var_dump($_POST);
?>

<?php echo '<h3>'. $message . '</h3>'?>
<span style="color: red;"><?php echo validation_errors(); ?></span>

<form action="<?php echo site_url() ?>/admin/auth/index" name="login_form" method="post" enctype="application/x-www-form-urlencoded">
    Email: <input name="user_email" id="user_email" value="" />
    <br>
    Password: <input type="password" name="user_password" id="user_password" value="" />
<br>
    <input type="submit" name="login_submit" id="login_submit" />
</form>

控制器驻留在/ application / controllers / admin中

提交后,我的CodeIgniter控制器中的post变量将丢失并为空 .

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

            echo '$_POST<hr>';
            var_dump($_POST);
?>

<form action="https://www.example.com.com/dashboard/login_test.php" name="login_form" method="post" enctype="application/x-www-form-urlencoded">
    Email: <input name="user_email" id="user_email" value="" />
    <br>
    Password: <input type="password" name="user_password" id="user_password" value="" />
    <br>
    <input type="submit" name="login_submit" id="login_submit" />
</form>

但是,如果我将以下表单放在/ dashboard /除CodeIgniter安装之外,我会收到所有POST变量 . 有趣的是,这发生在远程AWS EC2实例上,而在本地,在MAMP服务器上,CodeIgniter代码可以正常工作 .

有任何想法吗?

提前致谢 .

如果我以表单方法而不是POST切换到GET,则会在控制器和视图中提交和访问这些值 . 但是,我不想将密码作为URL参数提交 . 为什么帖子不能在AWS EC2上运行,而是在本地MAMP服务器上运行?

1 回答

  • 0

    请使用 base_url() 而不是 site_url() . 您可以尝试使用 echo base_url() 进行故障排除 .

    <form action="<?php echo base_url(); ?>admin/auth/index" name="login_form" method="post" enctype="application/x-www-form-urlencoded">
        Email: <input name="user_email" id="user_email" value="" />
        <br>
        Password: <input type="password" name="user_password" id="user_password" value="" />
    <br>
        <input type="submit" name="login_submit" id="login_submit" />
    </form>
    

    Editted .

    你的控制器应该搞这样的事情

    <?php
    
    if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
    class Login extends CI_Controller {
    
    	public function __construct() {
            parent::__construct();
            // Your own constructor code
        }
        
        function login(){
        	$data['message'] = 'Your message';
        	$this->load->view('login', $data);
        }
    
        function login_test(){
            echo $this->input->post('user_email');
        }
    }
    

    你的看法

    <?php echo '<h3>'. $message . '</h3>'?>
    <span style="color: red;"><?php echo validation_errors(); ?></span>
    
    <form action="<?php echo base_url() ?>admin/login_test" name="login_form" method="post" enctype="application/x-www-form-urlencoded">
        Email: <input name="user_email" id="user_email" value="" />
        <br>
        Password: <input type="password" name="user_password" id="user_password" value="" />
    <br>
        <input type="submit" name="login_submit" id="login_submit" />
    </form>
    

    这应该是 echo 的电子邮件地址 .

相关问题