• I’m writing a plugin to register and login to a codeigniter app we’ve got at the same time as registering and logging in to wordpress. the solution I came up with is to submit the form variables to the codeigniter login controller function “check_login” and after it confirms login on the codeigniter side it starts a session and populates some session variables before redirecting back to a worpress page. The session variables are then captured by a plugin function hooked into “wp_head” that logs them into wordpress and then unsets the variables.

    The problem I’m having is when I hit submit and it sends the form $_POST variables to “check_login” the variables don’t come through. I added:

    var_dump($_REQUEST);
    		exit();

    And nothing is being sent over. The plugin code is as follows:

    <?php
        /*
        Plugin Name: ABE-app-integration
        Description: Integrates registration and login with the ABE insurance app
        Version: 1.0
        Author: Eric Hylland
        License: GPL
        */
        /* Runs when plugin is activated */
        register_activation_hook(__FILE__,'ABE_integrator_install');
        /* Runs on plugin deactivation*/
        register_deactivation_hook( __FILE__, 'ABE_integrator_remove' );
        function ABE_integrator_install() {
        /* Creates new database field */
        add_option("ABE_integrator_data", 'Default', '', 'yes');
        }
        function ABE_integrator_remove() {
        /* Deletes the database field */
        delete_option('ABE_integrator_data');
        }
        /*Setup the admins page */
        if ( is_admin() ){
        /* Call the html code */
        add_action('admin_menu', 'ABE_integrator_admin_menu');
        function ABE_integrator_admin_menu() {
        add_options_page('ABE Integrator', 'ABE Integrator', 'administrator',
        'abe-integrator', 'ABE_integrator_html_page');
        }
        }
        /*Admin page layout*/
        function ABE_integrator_html_page(){
    	?>
    	<div>
    	<h2>ABE Integrator</h2>
    	</div>
        <?php
        }
        function ABE_loginlogo() {
          echo '<style type="text/css">
            h1 a {
              background-image: url("https://dev.alliedbeautyexperts.net/wp-content/uploads/2013/03/ABEWebsiteLogo.png") !important;
            }
            .login h1 a {
                background-size: 300px auto !important;
                width: 300px !important;
                height: 65px !important;
            }
          </style>';
        }
        add_action('login_head', 'ABE_loginlogo');
        function programmatic_login() {
            if(isset($_SESSION['AbeUser'])){
                if ( is_user_logged_in() ) {
                    wp_logout();
                }
    
                $username = $_SESSION['AbeUser'];
                $password = $_SESSION['AbePass'];
            add_filter( 'authenticate', 'allow_programmatic_login', 10, 3 );    //         hook in earlier than other callbacks to short-circuit them
            $user = wp_signon( array( 'user_login' => $username, 'user_password' =>$password ) );
            remove_filter( 'authenticate', 'allow_programmatic_login', 10, 3 );
            if ( is_a( $user, 'WP_User' ) ) {
                wp_set_current_user( $user->ID, $user->user_login );
                wp_set_auth_cookie( $user->ID );
                if ( is_user_logged_in() ) {
                    return true;
               unset($_SESSION['AbeUser']);
               unset($_SESSION['AbePass']);
               wp_redirect($_SERVER['REQUEST_URI']);
               exit;
            }
        }
        return false;
         }
        }
         function allow_programmatic_login( $user, $username, $password ) {
        return get_user_by( 'login', $username );
         }
        add_action( 'wp_head', 'programmatic_login' );
        function ABE_login_form(){
            $logForm = "
    	    <div style='display: inline-block; margin: 0 auto; width: 250px;'>
                <form action='/insuranceapp/index.php/common/login/check_login' method='post'>
    	    <input type='hidden' name='wp-submit' value='Login'>
               <input type='text' id='email' autocomplete='off' name='logemail' padding='12px' required pattern='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,3}$'>Username(Email)</input></br></br>
                <input type='password' id='password' name='logpassword' autocomplete='off' padding='12px' required>Password</input></br>
                </br><input type='submit'></input>
                </form>
    	    </div>
                </br>
            ";
            return $logForm;
        }
        add_shortcode( 'ABElog', 'ABE_login_form' );
        /*Add a shortcode to embed registration form*/
        function ABE_reg_form(){
        	$regform = "
    	    <div style='margin: 0 auto;'>
    	    <form action='/insuranceapp/index.php/common/registration/ABE_add_new_customer' method='post'>
    	    <div style='display: inline-block'><input type='text' id='first_name' value='Reg' name='first_name' autocomplete='on' padding='12px' required pattern='^[a-zA-Z]+$'>First Name</input></div>
    	    <div style='display: inline-block'><input type='text' id='last_name' value='test' name='last_name' autocomplete='on' padding='12px' required pattern='^[a-zA-Z]+$'>Last Name</input></div>
    	    <input type='text' id='contact_no' name='contact_no' padding='12px' autocomplete='on' value='3333333333' required pattern='(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}'>Phone</input><hr>
    	    <div style='display: inline-block'><input type='text' id='business_contact_no' value='9999999999' autocomplete='off' name='business_contact_no' padding='12px' required pattern='(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}'>Company Phone</input></div>
    	    <hr>
    	    <div style='display: inline-block'><input type='text' id='email' autocomplete='on' name='regemail' onchange='matchem()' padding='12px' required pattern='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,3}$'>Username (Email)</input></div>
    	    <div style='display: inline-block'><input type='text' id='conname' autocomplete='on' name='conname' onchange='matchem()' padding='12px' required pattern='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,3}$'>Confirm Username (Email)</input></div><div id='mismatch' style='display: none; margin: 10px;'><font color='red'>Usernames Must Match</font></div>
    	    <input type='password' id='password' name='regpassword' value='test' autocomplete='on' padding='12px' required>Password</input>
            <input type='hidden' name='city' value='Denver'></input>
            <input type='hidden' name='zip' value='000000'></input>
            <input type='hidden' name='state' value='CO'></input>
            <input type='hidden' name='security_question' value='What's your dogs name'></input>
            <input type='hidden' name='security_answer' value='Spot'></input>
            <input type='hidden' name='address' value='On Your Way'></input>
    	    </br></br><input type='submit'></input>
    	    </form>
    	    </br></br>
    	    <div>
    	    <font color='#6a6d6f' face='Arial, Verdana, Helvetica, sans-serif'><span style='font-size: 11.111111640930176px; line-height: 14px;'><a class='linkUtility' href='/terms-use/' target='_blank' style='margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: rgb(255, 255, 255); color: rgb(35, 112, 169);' title='terms of use'>Terms of Use</a><span style='background-color: rgb(255, 255, 255);'> and </span><a class='linkUtility' href='/privacy-policy/' target='_blank' style='margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: rgb(255, 255, 255); color: rgb(35, 112, 169);' title='privacy policy'>Privacy Policy</a><span style='background-color: rgb(255, 255, 255);'>.</span></span></font>
    	    </div>
    	    <script>
    	     function matchem(){
    	 	    if(document.getElementById('conname').value != '' && document.getElementById('conname').value !== document.getElementById('usename').value){
    	 		    document.getElementById('mismatch').style.display = 'inline-block';
    	 	    }else{
    	 		    document.getElementById('mismatch').style.display = 'none';
    	 	    }
    	     }
    	    </script>
    	</div>
    	";
    	return $regform;
        }
        add_shortcode( 'ABEreg', 'ABE_reg_form' );
        function ABE_complete_registration() {
            if(isset($_SESSION['ABE_Reg_email'])){
                $userdata = array(
                'user_login'    =>   $_SESSION['ABE_Reg_email'],
                'user_email'    =>   $_SESSION['ABE_Reg_email'],
                'user_pass'     =>   $_SESSION['ABE_Reg_pass'],
                'first_name'    =>   $_SESSION['ABE_Reg_fname'],
                'last_name'     =>   $_SESSION['ABE_Reg_lname'],
                'nickname'      =>   $_SESSION['ABE_Reg_fname'],
                'phone'         =>   $_SESSION['ABE_Reg_phone'],
                'description'   =>   $_SESSION['ABE_Reg_bphone']
                );
                $user = wp_insert_user( $userdata );
                unset($_SESSION['ABE_Reg_email']);
                unset($_SESSION['ABE_Reg_pass']);
                unset($_SESSION['ABE_Reg_fname']);
                unset($_SESSION['ABE_Reg_lname']);
                unset($_SESSION['ABE_Reg_phone']);
                unset($_SESSION['ABE_Reg_bphone']);
                echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
            }
        }
        add_action( 'wp_head', 'ABE_complete_registration' );
        ?>

    And below is the login controller of the codeigniter app. I can provide the registration code as well but I think I will solve both problems if I figure out one. When I started writing the plugin I did the login first, and it worked for a bit, until I started writing the registration portion.

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
        /**
         * This class is used for user home page purpose\
         * @author tudip
         */
        class login extends app_controller {
    	/**
    	 * This constructor overrides the parent constructor
    	 */
    	function __construct(){
    		parent::__construct();
    		$this->load->model('common/user_model');
    		$this->set_page_title("User Dashboard");
    		$this->set_active_menus(array('login'));
    	}
    	/**
    	 * This index is used to load home page of user
    	 */
    	public function index(){
    		redirect('../../login/');
    		//$this->parser->parse("common/login.tpl", $this->data);
    
    	}
        /**
    	 * This function call the validate_user_login of user_model to check login
    	 */
    	public function check_login(){
    		var_dump($_REQUEST);
    		exit();
    			try{
    			if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    				$this->set_page_message("Invalid username or password", "error");
    				$val = $this->user_model->validate_user_login($_REQUEST);
    				if($val){
    					$this->data['page_data']['user_id'] = $this->session->userdata('user_id');
    					$this->data['page_data']['email'] = $this->session->userdata('email');
    					$this->data['page_data']['user_name'] = $this->session->userdata('user_name');
    					$this->data['page_data']['username'] = $this->session->userdata('username');
    					$this->data['page_data']['first_name'] = $this->session->userdata('first_name');
    					$this->data['page_data']['last_name'] = $this->session->userdata('last_name');
    					$this->data['page_data']['parent_id'] = $this->session->userdata('parent_id');
    					$result = $this->user_model->count_parent_ids();
    					if($this->session->userdata('renew_parent_id')){
    						$this->data['page_data']['from_renew'] = ACTIVE;
    					}
                     $this->set_page_message("User login successfully done", "success");
    					$this->check_session_user();
    					//Added this to log into wordpress after authenticating with the insurance app"
                        if (!session_id()) {
    					  session_start();
    					}
    					$_SESSION['AbeUser'] = $this->session->userdata('email');
    					$_SESSION['AbePass'] = $_REQUEST['password'];
    					redirect('/membership-resources');
                }else{
    					$this->parser->parse("common/login.tpl", $this->data);
    				}
    			}else{
    				$this->set_page_message("Illegal Operation - Not allowed", "error");
    				redirect('../../login/');
    				//show_404('page',false);
    			}
    		}catch (Exception $e){
    			$this->handle_controller_exception($e);
    			$this->parser->parse("common/login.tpl", $this->data);
    		}
    	}

    I need some more eyes on this. It is getting incredibly frustrating. Currently the htaccess file in the base folder contains the standard WordPress rewrite rule. I can include the validate_user_login function as well, but I don’t think there is anything making it that far. Is WordPress somehow blocking the $_POST variables?

    EDIT- I just talked to our hosting provider and they passed me these errors:

    [Mon Mar 28 14:20:57 2016] [error] [client 50.243.152.182] exec used but not allowed in /home/alliedp5/public_html/development/500.shtml, referer: https://dev.alliedbeautyexperts.net/login/
        [Mon Mar 28 14:20:57 2016] [error] [client 50.243.152.182] SoftException in Application.cpp:256: File "/home/alliedp5/public_html/development/wp-content/plugins/mimetypes-link-icons/css/style.php" is writeable by group, referer: https://dev.alliedbeautyexperts.net/login/
  • The topic ‘Integrating WordPress with a Codeigniter app using $_POST variables’ is closed to new replies.