开发者

Use Drupal 6 APIs in custom webpage?

I want to have a non-Drupal website create a user account in my Drupal installation when a form is submitted. Is there a way to include (and otherwise initiate) the drupal APIs in a php script that is not inside a drupal module? I have tried including some inclu开发者_运维知识库de files as the "unknown function" errors keep coming up, but it has turned into a cat-and-mouse game.

Thank you for your help, Jeff


Yep, use services.module. It provides APIs for Drupal.

Or:

<?php

chdir('/path/to/drupal/');
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

edit: Per the comments, for command-line usage, you have to spoof $_SERVER stuff that Drupal relies on (particularly the domain name):

<?php

// set some server variables so Drupal doesn't freak out
$_SERVER['SCRIPT_NAME'] = '/script.php';
$_SERVER['SCRIPT_FILENAME'] = '/script.php';
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'POST';

// act as the first user
global $user;
$user->uid = 1;

// change to the Drupal directory
chdir('/path/to/drupal');

// Drupal bootstrap throws some errors when run via command line
//  so we tone down error reporting temporarily
error_reporting(E_ERROR | E_PARSE);

// run the initial Drupal bootstrap process
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// restore error reporting to its normal setting
error_reporting(E_ALL);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜