我想让一个非Drupal网站在提交表单时在我的Drupal安装中创建一个用户帐户。有没有办法在不在drupal模块中的PHP脚本中包含(以及以其他方式启动)drupal API?我已经尝试包含一些包含文件,因为“未知功能”错误不断出现,但它已经变成了猫捉老鼠的游戏。
感谢您的帮助, 杰夫
答案 0 :(得分:1)
是的,请使用services.module
。它为Drupal提供API。
或者:
<?php
chdir('/path/to/drupal/');
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
编辑:根据评论,对于命令行用法,您必须欺骗Drupal所依赖的$_SERVER
内容(特别是域名):
<?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);