Last Updated: February 25, 2016
·
1.107K
· ortuna

Drupal 6 bootstrap

Why you need it

Sometimes a Drupal install requires a script to do its dirty work or clean up. This is a quick way to add a script and run it with php myscript.php and interact with a Drupal 6 install.

Code
<?php

$_SERVER['SCRIPT_NAME'] = '/metadata.php';
$_SERVER['SCRIPT_FILENAME'] = '/metadata.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'POST';
$_GET['q'] = '';
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Now you can do some work! e.g.

$node = node_load($nid);
$node->title = "My new title";
node_save($node);

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside