I have a non-Drupal PHP script I would like to put on a D7 Drupal site, but I would like it to be available only to users who have logged in via Drupal. What are the best/easiest ways to do this? It's my script, so I can change it any way I want, embed it in a module, a PHP-capable field, etc.

To be specific, it's a signup sheet system that uses form submissions, using files (not the db) to store the data.

2 Answers 2


You can wire up your script via a hook_menu, and instead of returning the output to render via Drupal, you can print it directly and exit at the bottom of the function. The submission handler would do the same thing, but drupal_goto() at the end.

That said, this is a moderately bad idea for the long run.

A better solution would be to use Webforms. Webforms are really easy to make, get stored in the database, and can be exported to Excel. I wouldn't be surprised if there is webform hook available so you could do your filesystem thing, too.

Another option is to use the Forms API to make your form w/ your custom validation and submission handlers.

  • For more info about my signup sheets requirements, see drupal.stackexchange.com/questions/19178/complex-signup-sheets. Unfortunately neither Webforms nor a homegrown Form solve the problem. Feb 9, 2012 at 16:52
  • Forms API lets you do pretty much anything you could image that involves user data and the database. I wouldn't rule it out as a solution.
    – mpdonadio
    Feb 9, 2012 at 21:22
  • I agree, the long-term solution is to Drupalize the script or find some Drupal-based substitute. But in the short term, it sounds like hook_menu() and checking permissions as user1359 suggested is the way to go. Do you agree? Feb 10, 2012 at 0:37
  • Implmenting hook_menu pretty much implies setting "access arguments" and/or "access callback" arguments, so yeah, this would likely fit the bill.
    – mpdonadio
    Feb 10, 2012 at 1:34

Another option, though you might find it to be too much work, is to roll your functionality up in a module. With a hook_menu call back, you can have the the module run any php code you define. So you would get both your Drupal authentication and your PHP functionality all in one go :)

Edit You would have to create a permission hook in order to limit access to it.

  • 1
    But you wouldn't get any Drupal authentication with this solution, you'd just get your PHP into Drupal. If you want authentication, you need to look at the answer @MPD has given.
    – Chapabu
    Feb 9, 2012 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.