From 846fa83122b99fb6f668726b5148b1f9c7ad28d6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 11 Nov 2007 08:54:02 +0000 Subject: - Patch #189395 by Gabor and Keith: fixed insecure instructions in documentation. Woops. --- modules/php/php.module | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'modules/php') diff --git a/modules/php/php.module b/modules/php/php.module index 681fd70b7..cf8513a8a 100644 --- a/modules/php/php.module +++ b/modules/php/php.module @@ -30,27 +30,35 @@ function php_filter_tips($delta, $format, $long = false) { case 0: return t('You may post PHP code. You should include <?php ?> tags.'); case 1: - return t(' -

Using custom PHP code

-

If you know how to script in PHP, Drupal gives you the power to embed any script you like. It will be executed when the page is viewed and dynamically embedded into the page. This gives you amazing flexibility and power, but of course with that comes danger and insecurity if you don\'t write good code. If you are not familiar with PHP, SQL or with the site engine, avoid experimenting with PHP because you can corrupt your database or render your site insecure or even unusable! If you don\'t plan to do fancy stuff with your content then you\'re probably better off with straight HTML.

-

Remember that the code within each PHP item must be valid PHP code - including things like correctly terminating statements with a semicolon. It is highly recommended that you develop your code separately using a simple test script on top of a test database before migrating to your production environment.

-

Notes:

-

A basic example:

-

You want to have a box with the title "Welcome" that you use to greet your visitors. The content for this box could be created by going:

+ $output = '

'. t('Using custom PHP code') .'

'; + $output .= '

'. t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') .'

'; + $output .= '

'. t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') .'

'; + $output .= '

'. t('Notes:') .'

'; + $output .= ''; + $output .= '

'. t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') .'

'; + $output .= '
'. t('

Add a custom block to your site, named "Welcome". With its input format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:

-print t("Welcome visitor, ... welcome message goes here ...");
+print t(\'Welcome visitor! Thank you for visiting.\');
 
-

If we are however dealing with a registered user, we can customize the message by using:

+

To display the name of a registered user, use this instead:

 global $user;
 if ($user->uid) {
-  print t("Welcome $user->name, ... welcome message goes here ...");
+  print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => $user->name));
 }
 else {
-  print t("Welcome visitor, ... welcome message goes here ...");
+  print t(\'Welcome visitor! Thank you for visiting.\');
 }
-
-

For more in-depth examples, we recommend that you check the existing Drupal code and use it as a starting point, especially for sidebar boxes.

'); +') .'
'; + $output .= '

'. t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', array('@drupal' => url('http://drupal.org'), '@php-snippets' => url('http://drupal.org/handbook/customization/php-snippets'))) .'

'; + return $output; } } } @@ -75,3 +83,6 @@ function php_filter($op, $delta = 0, $format = -1, $text = '') { return $text; } } + + + -- cgit v1.2.3