在自定义网页中使用 Drupal 6 API?

发布于 2024-11-19 13:11:29 字数 164 浏览 0 评论 0原文

我希望在提交表单时让非 Drupal 网站在我的 Drupal 安装中创建一个用户帐户。有没有办法在不在 drupal 模块内的 php 脚本中包含(或以其他方式启动)drupal API?我尝试过包含一些包含文件,因为“未知功能”错误不断出现,但它已经变成了猫捉老鼠的游戏。

感谢您的帮助, 杰夫

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 include 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡的优雅 2024-11-26 13:11:29

是的,使用 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文