
کد PHP سفارشی، میتواند در بخشهایی از محتوای سایت، همچون پست ها و بلوکها مورد استفاده واقع شود. با وجود آنکه استفاده از کدهای PHP در یک پست یا بلوک میتواند قدرت و انعطاف فراوانی برای کاربران مورد اعتماد با تجربه PHP کافی فراهم بیاورد، در عین حال میتواند در صورت استفاده نادرست حفره امنیتی خطرناکی پدید بیاورد. حتی یک اشتباه کوچک در هنگام پست نمودن کد PHP میتواند تصادفاً عملکرد کل سایت را مختل نماید.
اگر شما با PHP , SQL یا دروپال آشنایی ندارید، از بکار بردن کد های PHP در پست ها پرهیز کنید.این کد ها میتوانند بانک اطلاعاتی شما را تخریب کنند، وب سایت شما را غیر قابل استفاده کنند، و یا امنیت وب سایت شما را با مخاطرات جدی روبرو کنند.
توجه:
register_globals
is turned off. If you need to use forms, understand and use the functions in the Drupal Form API.print
or return
statement in your code to output content.template.php
file rather than embedding it directly into a post or block.A basic example: Creating a "Welcome" block that greets visitors with a simple message.
Add a custom block to your site, named "Welcome" . With its text format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:
print t('Welcome visitor! Thank you for visiting.');
To display the name of a registered user, use this instead:
global $user;if ($user->uid) {print t('Welcome @name! Thank you for visiting.', array('@name' => format_username($user)));}else {print t('Welcome visitor! Thank you for visiting.');}
Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.