Search code examples
phpdrupal-7

How to add hook in seperate php page in drupal?


I have submitted form values from my core php site through curl to drupal site(http://xxyz.com/drupal_hook_register.php) link. In this page i am trying to insert email,password directly into drupal database. Please help me to resolve this

         // define static var
       define('DRUPAL_ROOT', getcwd()); 
        // include bootstrap
       include_once('./includes/bootstrap.inc');
       // initialize stuff
        drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

        $email = $_REQUEST['email'];
         $password = $_REQUEST['password'];

Solution

  • Here you go!

    if($_POST) {
        //Bootstraping Drupal 
        require_once './includes/bootstrap.inc';
        drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    
        $account = new stdClass();
        $account->name = $_REQUEST['username'];
        $account->mail = $_REQUEST['mail'];
        $account->init = $_REQUEST['mail'];
        $account->pass = user_password($_REQUEST['pass']); // you could use a random characters here too
        $account->status = 1;
        user_save(Null, $account);
        if ($account->uid) {
          drupal_set_message('Created new user with id %uid', array('%uid' => $account->uid));
          echo 'success';
        }
    }
    

    Try this as this could help you!