Question

Fairly new to both php and Drupal. I have searched for this answer, and have found the one everyone keeps repeating, but I cannot get it to work.


What I've done, is create a form that accesses an 'external' php file, located in the root folder. (I have a lot of trouble wrapping my head around modules, so for me, this was an easier path). Within this php file, I am attempting to grab the uid of the current user to be stored in a table.

The solution I've found is to load bootstrap.inc, but I've failed miserably every time. The one thing I thought might have been the issue, is that I have loaded Drupal 7 into a sub-domain.


I'm obviously not changing the correct element, so e.g. lets say my domain is http://apples.fruitrocks.com. What do I change below, to get this to work?

define('DRUPAL_ROOT', '/var/www/vhosts/mysite.com/httpdocs/');
$_SERVER['HTTP_HOST'] = 'mysite.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Was it helpful?

Solution

I strongly advise against trying to bootstrap drupal from an external script.

A much simpler solution for you would be to create a page, and put all the processing in the theme file for that page. If the page you created has nid X, create page--X.tpl.php and put whatever you want there.

Remember that this method is "dirty" and in the long run when you are more comfortable with writing modules you should not put this logic in the theme files. But for now, I think this is your best bet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top