مقاله: ايجاد تغييرات در php.ini (انگليسي)

oxygenws

Active Member
در این تاپیک و در دو بخش مقاله ای از سایت builder.com را می چسبانم که توضیحات جالب و کاملی از انواع ایجاد تغییرات عمومی در فایل php.ini نوشته.

توجه کنید که تعدادی از این تغییرات مختص PHP 5 می باشد.
 

oxygenws

Active Member
قسمت اول:

کد:
***The PHP configuration file***

Before beginning with the tour, a quick note on how PHP's configuration file is structured. This file is named php.ini for a reason�it follows the INI file structure popular in many Windows applications. It's an ASCII text file is broken into named sections, each containing variables related to that section. Each section looks something like this:
[MySection]
variable="value"
anothervariable="anothervalue"

The section name is in square braces at the top, followed by any number of name-value pairs, with each pair on a separate line. As with regular PHP code, variable names are case sensitive and cannot contain spaces, while the values may be numeric, string, or Boolean.

Semicolons placed at the beginning of a line serve as comment markers. This makes it easy to enable or disable PHP features; rather than deleting a line, you can comment it out so that it isn't parsed. This is handy if you think you might want to re-enable a feature at a later date, you don't have to delete it out of the file.

In order for PHP to recognize it, the php.ini file must be located either in the current directory, the directory defined in the $PHPRC environment variable, or the directory specified at compile time (for Windows PHP, this is the main Windows directory).

After making changes to PHP's configuration through the php.ini file, you'll need to restart the Web server for your changes to take effect (assuming, of course, that you're using PHP through the Web server). For command-line usage of PHP, the configuration file will be read every time you invoke the PHP binary program.

کد:
***Setting parser options***

The first stop on this tour is also one of the more important ones: options related to the language interpreter. The first item here is the engine variable, which controls whether the PHP engine should be "on" or "off". Turning the engine off means that embedded PHP code will not be parsed by the Web server. It doesn't usually make sense to do this, so leave it on.
engine = On

The short_open_tag variable controls whether the parser should recognize the shortcut <?...?> tags, as well as the standard <?php...?> tags. Turn this off if you anticipate conflicts with other languages, or if you want to apply strict syntactical rules to your PHP code.
short_open_tag = On

Normally, session, cookie or HTTP header data in a PHP script must be sent before any output is generated by the script. If this is not possible in your application, you can enable what PHP calls output buffering, with the output_buffering variable.

With output buffering on, PHP stores the output of your script in a special memory buffer and sends it only when explicitly told to do so. This allows you to send special HTTP headers and cookie data even in the middle or at the end of your script; however, it can degrade performance marginally.
output_buffering = Off

You can also pass the output_buffering variable a number indicating the size of the buffer, for example:
output_buffering = 2048

When PHP starts up, it adds a message stating its version number to the Web server's standard header. To turn this off, set the expose_php variable to false. This is useful if, for example, you want to mask the capabilities of your Web server from potential hackers.
expose_php = On

کد:
***Setting the PHP search path***

You can set a search path for PHP with the include_path variable, which accepts a list of directories. PHP will automatically check these directories when it encounters references to files without a path prefix.

If you have function libraries or classes that you use frequently, list their locations here to simplify file lookups. This is also a good place to add the path to PHP's PEAR directory, which contains many reusable classes.
include_path = ".:/usr/local/lib/php/pear:"

Windows users can specify multiple locations by separating them with semicolons; UNIX users must use colons instead.

Two interesting variables in this context are auto_prepend_file and auto_append_file. These variables specify files that PHP automatically appends to the beginning or end of any PHP document. This is mostly used to append a header or footer to pages generated in PHP, saving you a few lines of code in each PHP document you write. The downside is that the files specified here will be appended to *all* PHP documents, so these variables are best suited for single-application servers.

The files may be either PHP scripts or regular HTML documents. Embedded PHP code must be surrounded by the standard <?php...?> tags:
auto_prepend_file = /home/web/includes/header.php
auto_append_file = /home/web/includes/legal.php

کد:
***Handling errors***

PHP errors fall into four categories: parsing errors, notices about code bugs such as uninitialized variables, warnings (aka non-fatal errors), and fatal errors. Normally, when PHP encounters either a parsing, non-fatal or fatal error, it displays the error and�if the error is fatal�also stops script processing at that point. You can alter this behavior with the error_reporting variable, which accepts a bitfield of error codes and only displays errors matching those codes.
error_reporting =� E_ALL

To turn off the display of errors�recommended in production code�set the display_errors variable to false, and instead write the messages to an error log with the log_errors variable.

Doing this is good for security too�by turning off errors, you hide system-specific information that unscrupulous users could use to try and damage your site or application. You should instead write these errors to a custom log file or to the system logger, by setting the error_log variable to either a file name or the special value "syslog". Remember to check these log files regularly to keep an eye on what's happening inside your application.
display_errors = Off
log_errors = On
error_log = "error.log"

Come back Thursday (July 22) for the second part of this tutorial. I'll take you deeper into the php.ini file, showing you the settings to configure file uploads and form parsing, run PHP in restricted mode for greater security, activate extensions, set resource limits for memory usage, and disable legacy features for better performance.
 

oxygenws

Active Member
قسمت دوم:

کد:
***Activating extensions***

A number of different extensions are available for PHP. On UNIX systems, extensions need to be built at compile-time; on Windows, binary DLL files are included with the PHP distributions. The extension_dir variable contains the name of the directory PHP should look in for these extensions.
extension_dir = "C:\Program Files\Internet Tools\Apache\bin\php4\extensions"

The Windows PHP distribution comes with over 20 different extensions, and they're all listed (though commented out) in the php.ini file. To activate a particular extension, simply remove the semicolon at the beginning of the line and restart the server. To deactivate an extension (say, for better performance), add a semicolon to comment out the line.

If the extension is not listed in the file, use the extension variable, and pass it the file name of the corresponding DLL.

extension=php_domxml.dll

extension=php_dbase.dll

کد:
***Setting extension-specific variables***

Extension-specific variables are stored in separate sections of the configuration file. For example, all the variables related to the MySQL extension should be in the [MySQL] section of the php.ini file.

If you're going to use PHP's mail() function, there are three variables you may need to set. The SMTP and sendmail_from variables (on Windows) or the sendmail_path variable (on UNIX) are used when sending e-mail messages through PHP's mail() function. On Windows, these variables set the SMTP server to be used and the From: address to display in e-mail messages; on UNIX, the sendmail_path variable sets the path of the MTA (mail transfer agent) for mail delivery:

SMTP = myserver.localnet.com

sendmail_from = [email][email protected][/email]

sendmail_path = /usr/sbin/sendmail

The java.class.path, java.home, java.library and java.library.path variables all set the directories to look in for Java classes and libraries. These values are used by the Java extension, so make sure you set them correctly if you want PHP to integrate correctly with your Java applications:

java.class.path = .\php_java.jar

java.home = c:\jdk

java.library = c:\jdk\jre\bin\hotspot\jvm.dll

java.library.path = .\

The session.save_path variable specifies the temporary directory for session information. Normally, this defaults to /tmp, but since this directory does not exist on Windows systems, you must reset it to the appropriate Windows temporary directory or else the session handler will pop up unsightly error messages whenever you call session_start(). You can also control how long a session cookie remains valid, in seconds, with the session.cookie_lifetime variable:

session.save_path = c:\windows\temp

session.cookie_lifetime = 1800

کد:
***Security settings***

There are a number of variables in php.ini related to the security of your PHP installation. The most interesting of these is the safe_mode variable, recommended for ISPs and shared-hosting services as it limits the things a user can do with PHP:

safe_mode = Off

With safe mode turned on, you can specify which directories are searched for files with the safe_mode_include_dir variable. You can also restrict the types of programs a PHP script can run with the exec() command by placing the program binaries in a special directory and telling PHP about it via the safe_mode_include_dir variable. Only binaries in this directory will be accessible via exec():

safe_mode_include_dir = /usr/local/lib/php/safe-include

safe_mode_exec_dir = /usr/local/lib/php/safe-bin

You can restrict file operations with the open_basedir variable, which sets the named directory as the root for file operations. When this value is set, files outside the named directory tree will be inaccessible to PHP. This is a good way to restrict a shared system's users to their own home or Web directories:

open_basedir = /home/web/

The max_execution_time variable sets the maximum number of seconds PHP will wait for a script to finish executing before forcibly terminating it. This comes in handy when your script spirals into an infinite loop. However it can trip you up if you have a legitimate activity that takes time to complete�for example, a large file upload. In such situations you should consider increasing this value to avoid having PHP shut down your script when it's in the middle of something important.

max_execution_time = 90

کد:
***Configuring file uploads and form variables***

If the security configurations we discussed earlier aren't enough, you can secure your system even further by either turning off file uploads, through the file_uploads variable, or by setting a limit on the maximum size of an upload with upload_max_filesize. Generally you'll want to set a fairly small file size unless you have an application that is designed to accept files, such as an image gallery or a Web-based FTP service:

file_uploads = On

upload_max_filesize = 2M

If you're not interested in uploading files but use a lot of forms in your PHP application, there are two variables that will be of particular interest to you�first, the register_globals variable, the cause of much heartache to longtime PHP developers. In PHP 3.x, this variable was On by default, leading form variables to be automatically converted to PHP variables when a form was submitted.

Security concerns led to this variable being set to Off in PHP 4.x. As a result, form variables could only be accessed through the special $_GET and $_POST arrays. This broke many scripts written in PHP 3.x, and forced developers to rewrite and retest their scripts. For example, the value entered into the field <input type="text" name="email"> would be available as $email in a PHP 3.x script, but as $_POST['email'] or $_GET['email'] in a PHP 4.x script.

You should generally set this variable to Off, as that offers greater security against script attacks through forms. For compatibility with older PHP 3.x scripts, turn it On:

register_globals = Off

Also related to form submission is the post_max_size variable, which controls the maximum amount of data that PHP will accept in a single form submission with the POST method. It's unlikely you'll ever need to increase this from the default value of 8 MB; instead, you should probably reduce it to a more realistic figure. However, if you're planning on using the file upload features of PHP, keep this value greater than the value of upload_max_filesize.

post_max_size = 8M

New in PHP 5 is the max_input_time variable, which sets a time limit in seconds for receiving input data through POST, GET, and PUT. If your application is running over a slow link, it is sometimes worthwhile to explore increasing this value to allow the script more time to receive input data.

max_input_time = 90

کد:
***Tweaking performance***

There are even some values you can tweak to improve the performance of the PHP interpreter. In order to avoid runaway scripts using up all the available memory on the system, PHP allows you to define limits on memory usage. This value is set via the memory_limit variable, and it specifies the maximum memory a single script may use:

memory_limit = 8M

The memory_limit value should generally be higher than the value of post_max_size.

Another thing you can do to improve performance is disable the $argc and $argv variables, which store the number of arguments passed to an application on the command line as well as the actual argument values.

register_argc_argv = false

Similarly, disable the $HTTP_GET_VARS and $HTTP_POST_VARS arrays, since you're unlikely to use them in the modern world of $_GET and $_POST. Disabling these features can improve performance, but is only available in PHP 5 via the register_long_arrays variable.

register_long_arrays = false

کد:
***The ini_set() function***

Finally, a note on the ini_set() function. While PHP reads all its settings at startup from the php.ini configuration file, it also lets you override those settings on a per-script basis with the very cool ini_set() function. This function accepts two arguments: the name of the configuration variable to alter, and its new value. Here is an example, which increases the maximum execution time for the script in which it appears:

<?php

ini_set('max_execution_time', 600);

// more code

?>

The setting only affects the script in which it is set. Once the script has completed executing, the original value of the variable is restored automatically.

If your PHP applications are running on a shared server, it's unlikely that you will have access to the master php.ini configuration file. The ini_set() function can help significantly by allowing you to reconfigure PHP on the fly for your special needs.
 

Bijan

New Member
آقا oxygenws سلام!! چطور هستين؟!

شما که اينقدر PHP بلديد چرا جواب سوال منو تو IranPHP قسمت نصب و راه اندازي PHP نميدين! من هر کاري ميکنم نمي تونم MySQL را در PHP5 راه بندازم! با اينکه فايل mysql.dll را دارم و مسير extension_dir را هم درست وارد کردم، ولي بازم پيغام ميده که نميشناسه mysqll.dll را، ولي اين مشکل را براي gd2 که در همون شاخه هست ندارم!

جواب منو بديد لطفا!
مرسي!
 

taher007

Member
دوستانی که براشون جالب بوده...
میشه چند موردش رو برای ما هم توضیح بدبد!!
 

Bijan

New Member
من که از رنگش خيلي خوشم اومد! حقيقتش سبز يکي از رنگهاي مورد علاقه منه! در ضمن کادر آبي دورش هم خيلي قشنگ بود! ولي ميدونيد چيه؟ از همه قشنگتر اون ماهيست که داره دمشو (ماهي هم دم داره؟) تکون ميده! خلاصه از همه نظر جذاب بود!
 

oxygenws

Active Member
مترجمان:
فرشاد پايدار
[email protected]
جابر صادقي
www.rahacomputer.g3z.com



فايل پيکربندي PHP
قبل از شروع مطالب نگاهي اجمالي به ويژگيهاي فايل پيکربندي PHP منطقي به نظر مي رسد. نام اين فايل php.ini مي باشد و به دلايلي از ساختار کلي فايلهاي ini که بيشتر در برنامه هاي کاربردي ويندوز استفاده مي شود، پيروي مي کند. اين فايل متني به صورت ASCII مي باشد که به بخشهايي (session) تقسيم مي شود. هر بخش متغيرهايي را که مربوط به آن بخش مي شوند، در بر مي گيرد. هر بخش چيزي شبيه زير مي باشد:
کد:
[MySection] 
variable="value" 
anothervariable="anothervalue"

نام بخش در يک جفت براکت"[]" در بالا قرار مي گيرد. و زير آن در هر سطر يک متغير با مقدارش قرار مي گيرد. متغيرها به حروف حساس (case sensitive) هستند و نمي توانند شامل فاصله (space) باشند، در حالي که مقادير متناظر آنها مي توانند اعداد، رشته کاراکتري (string) و يا Boolean باشند.

سمي کالن ";" در ابتداي هر سطر به عنوان نشانگر درج توضيحات (comment) مي باشد. اين راهي ساده براي فعال يا غيرفعال کردن ويژگيهاي PHP مي باشد، به جاي حذف کردن يک سطر مي توانيد به اين روش آن را به توضيح تبديل کرده که در پردازش فايل ها شرکت نخواهد کرد. در صورتي که فکر مي کنيد ممکن است بعد ها بخواهيد از ويژگي که اکنون به کارتان نمي آيد، استفاده کنيد بهتر است آن را پاک نکنيد.

براي اينکه PHP بتواند فايل php.ini را تشخيص بدهد بايد آن را در دايرکتوري جاري، دايرکتوري که در متغير $PHPRC تعريف شده، يا دايرکتوري که هنگام کامپايل مشخص شده است(براي ويندوز اين همان دايرکتوري اصلي PHP است) نگهداريد.

بعد از اينکه شما تغييراتي در فايل php.ini داديد براي آنکه تغييرات اعمال شوند بايد سرور خود را مجددا راه اندازي نماييد (سرور را restart کنيد). البته فرض بر اين است که شما قبلا در حال استفاده PHP بر سرور خود بوده ايد. براي استفاده هاي command-line از PHP فايل پيکربندي php.ini در هرباري که برنامه PHP احضار مي شود خوانده و چک مي شود.


تنظيم ويژگيهاي مفسر
اولين مرحله در اين مقاله از مهمترين گامهاي آن مي باشد، ويژگيهايي که به مفسر زبان PHP مربوط مي شود. اولين مورد در اينجا engine variable مي باشد که چک مي کند که PHP engine بايد فعال "on" يا غير فعال "off" باشد. Off کردن اين متغير به معني اين است که کدهاي PHP توسط سرور تفسير نشوند.معمولاً نيازي به اين تغيير حس نمي شود، پس اين متغير را به صورت on رها کنيد.
کد:
engine=On

متغير short_open_tag کنترل مي کند که آيا مفسر بايد تگهاي کوتاه <?....?> را همانند تگ استاندارد <?php…?> تشخيص دهد يا نه.در صورتي که تشخيص مي دهيد اين نمونه تگها باعث ناسازگاري با ديگر زبانها مي شوند يا اينکه تصميم به استفاده از قوانين syntax مختص PHP داريد مي توانيد آن را off کنيد.
کد:
short_open_tag = On

معمولاً session, cookie و اطلاعات HTTP header در يک اسکريپت PHP بايد قبل از توليد هرگونه خروجي توسط آن اسکريپت فرستاده شوند. در صورتي که اين در برنامه شما امکان پذير نيست مي توانيد هر چه را که PHP به نام output buffering مي شناسد، توسط متغيرهاي output_buffering فعال کنيد.

با on بودن output buffering، زبان PHP خروجي اسکريپت شما را در يک بافر مخصوص نگه مي دارد و هنگامي آنها را مي فرستد که به طور مشخص به آن دستور داده شود. اين به شما امکان مي دهد که cookieها يا اطلاعات HTTP header را از وسط يا انتهاي کد اسکريپت خود بفرستيد. هرچند اين مي تواند کارآيي را در حاشيه کاهش دهد.
کد:
output_buffering = Off

شما مي توانيد با يک عدد به عنوان مقدار براي متغير output_buffering اندازه بافر را تعيين کنيد.
کد:
output_buffering = 2048

هنگامي که PHP شروع به کار مي کند يک پيام حاوي شماره نسخه خود به هدر استاندارد سرور مي افزايد.براي غيرفعال کردن آن مي توانيد متغير expose_PHP را off کنيد.اين مي تواند مفيد باشد، مثلا اگر بخواهيد امکانات وب سرور خود را از ديد هکرها پنهان کنيد.
کد:
expose_PHP = On


تنظيم مسير جستجوي
شما مي توانيد مسير جستجويي را براي PHP با تنظيم متغير include_patch که ليستي از مسيرها را مي پذيرد، مشخص کنيد. PHP هنگامي که با فايلي که مسير آن مشخص نشده است ، مواجه مي شود به طور اتوماتيک اين مسيرها را چک مي کند.
اگر شما کتابخانه اي از توابع يا مجموعه اي از کلاسها داريد که زياد از آنها استفاده مي کنيد مي توانيد دايرکتوري موقعيت آنها را در اين متغير قرار دهيد. همچنين اين متغير مکان مناسبي براي اضافه کردن دايرکتوري PEAR خود PHP مي باشد، که مجموعه اي از کلاسهايي که بسيار استفاده مي شوند را شامل مي شود.
کد:
include_path = ".:/usr/local/lib/php/pear:"

کاربران ويندوز براي مشخص کردن چندين دايرکتوري بايد از سمي کالن";" بين آنها استفاده کنند و کاربران unix از کالن ":".

دو متغير جالب در اين زمينه auto_prepend_file و auto_append_file مي باشند. اين متغيرها فايلهايي را مشخص مي کنند که PHP به ابتدا يا انتهاي هر سند PHP اضافه خواهد کرد. اين مورد بيشتر براي اضافه کردن header و footer به صفحاتي است که توسط PHP ايجاد مي شوند، به طوري که باعث مي شود تعدادي خط کد به هر سند PHP که شما مي نويسيد اضافه گردد.
اين فايلها هم مي توانند اسکريپتهاي PHP و هم html معمولي باشند، ولي کدهاي PHP براي اين امر بايد در تگ استاندارد <?php…..?> محصور شده باشند.
کد:
auto_prepend_file = /home/web/includes/header.php
auto_append_file = /home/web/includes/legal.php


چگونگي رفتار با خطاها
خطا ها در PHP در چهار دسته مي آيند: parsing errors يا خطاي زمان تجزيه (کامپايل)، تذکرات درمورد خطاهاي موجود در کد مثلا مقدار دهي نکردن يک متغير، warning يا هشدار و fatal error. معمولا هنگامي که PHP با يکي از خطاهاي parsing error يا warning يا fatal error مواجه مي شود، خطاها را نمايش مي دهد و اگر خطا از نوع fatal error باشد اجراي اسکريپت را در همان نقطه متوقف مي کند. شما مي توانيد اين رفتار را با متغير error_reporting که چند فيلد خطا را مي گيرد و تنها خطاهايي را که با آنها سازگار باشند نمايش مي دهد، اصلاح کنيد.
کد:
error_reporting = E_ALL

براي غير فعال کردن نمايش خطاها مقدار متغير display_errors را به نادرست تغيير دهيد و به جاي آن پيام خطاها را در ثبات خطاها از طريق متغير log_errors بنويسيد.
انجام اين کار براي امنيت بيشتر مفيد است، با غيرفعال کردن نمايش خطا شما اطلاعات ويژه سيستم خود را مخفي مي کنيد بدون توجه به اينکه آيا کاربران قصد خراب کردن سايت شما را دارند يا فقط استفاده مي کنند.به جاي آن شما بايد خطاها را در يک فايل دلخواه يا ثبات خطاي سيستم (system logger)، با تنظيم مقدار متغير error_log به مسير فايل انتخابي يا مقدار پيش فرض "syslog"، ثبت کنيد. فقط به ياد داشته باشيد که مرتبا به اين فايل سربزنيد تا ببينيد که در برنامه شما چه خطاهايي وجود دارد.
کد:
display_errors = Off 
log_errors = On 
error_log = "error.log"


فعال کردن توسعه ها
توسعه هاي متعددي براي PHP موجود است. در سيستمهاي يونيکس لازم است که اين توسعه ها در زمان کامپايل ساخته شوند. در ويندوز، dll هاي باينري وجود دارند که بايد ضميمه شوند. متغير extension_dir محتوي نام شاخه اي است که PHP در آن به دنبال اين توسعه ها مي گردد. مثلا:
کد:
extension_dir = "C:\Program Files\Internet Tools\Apache\bin\php4\extensions"

نسخه ويندوز PHP به همراه ۲۰ توسعه منتشر مي شود که تمامي آنها در فايل php.ini ليست شده اند. براي فعال کردن هر توسعه، علامت سمي کالن جلوي آن را حذف کرده و سرور خود را از نو راه اندازي کنيد. براي غير فعال کردن يک توسعه نيز مي توانيد جلوي آن علامت سمي کالن رو اضافه کنيد.

اگر توسعه مورد نظرتان در ليست توسعه ها در فايل php.ini نيست از متغير extension استفاده کرده و نام dll مورد نظر را به آن نسبت دهيد. مثلا:
کد:
extension=php_domxml.dll 
extension=php_dbase.dll


تنظيم متغيرهاي مربوط به توسعه ها
متغير هاي مربوط به توسعه ها، در بخش جداگانه اي از فايل پيکربندي (php.ini) ذخيره مي شوند. براي مثال تمام متغيرهايي که به توسعه هاي MySQL مربوط مي شوند بايد در قسمت [MySQL] در فايل php.ini، قرار بگيرند.

اگر قصد استفاده از تابع mail در PHP را داريد، 3 متغير وجود دارد که بايد آنها را تنظيم کنيد. متغيرهاي SMTP و sendmail_from (در ويندوز) يا sendmail_path (در يونيکس) در هنگام ارسال e-mail از طريق تابع mail مورد استفاده قرار مي گيرند. در ويندوز اين متغير ها براي تنظيم SMTP Server و همچنين براي تعيين آدرس From در ساختار e-mail به کار مي روند. در يونيکس متغير sendmail_path مسير MTA يا Mail Transfer Agent را براي ارسال mail تنظيم مي کند.
کد:
SMTP = myserver.localnet.com
sendmail_from = [email][email protected][/email]
sendmail_path = /usr/sbin/sendmail

متغيرهاي java.class.path ، java.home، java.library و java.library.path همگي آدرس کلاس ها و کتابخانه هاي جاوا را تنظيم ميکنند. اين مقادير به وسيله توسعه هاي جاوا مورد استفاده قرار مي گيرند. بنابراين اگر مي خواهيد PHP بتواند ارتباط صحيحي با برنامه هاي جاواي شما برقرار کند از درستي و معتبر بودن مقادير اين متغير ها اطمينان حاصل کنيد.
کد:
java.class.path = .\php_java.jar
java.home = c:\jdk
java.library = c:\jdk\jre\bin\hotspot\jvm.dll
java.library.path = .\

متغير session.save_path مشخص کننده آدرس شاخه موقتي است که براي ذخيره اطلاعات session ها بکار مي رود. معمولا اين متغير به طور پيش فرض مقدار /tmp را دارد، اما از آنجا که اين شاخه در ويندوز وجود ندارد بايد آن را با آدرس درست شاخه موقت ويندوز تصحيح کنيد در غير اين صورت هنگام فراخواني دستور session_start با خطا مواجه مي شويد. همچنين مي توانيد با تنظيم متغير session.cookie_lifetime مدت اعتبار cookie هاي session را بر حسب ثانيه مشخص کنيد.
کد:
session.save_path = c:\windows\temp
session.cookie_lifetime = 1800


تنظيمات مربوط به امنيت
تعدادي متغير در php.ini وجود دارد که به امنيت PHP نصب شده بر روي سيستم شما مريوط مي شوند. مهمترين آنها متغير safe_mode مي باشد که به طور مثال استفاده از آن براي محدود کردن آنچه کاربر مي تواند از طريق PHP انجام دهد بهISP ها توصيه ميشود.
کد:
safe_mode = Off

اگر safe mode فعال باشد (safe_mode = on) مي توانيد با تنظيم متغير safe_mode_include_dir مشخص کنيد که کدام شاخه ها براي فايل ها مورد جستجو قرار بگيرند. همچنين ميتوانيد نوع برنامه هايي که کدهاي PHP مي توانند از طريق فرمان exec آنها را اجرا کنند، را محدود کنيد. بدين منظور بايد اين برنامه هاي مجاز را در يک شاخه مخصوص قرار دهيد و از طريق متغير safe_mode_include_dir به PHP بگوييد که تنها در آن شاخه به دنبال آنها بگردد.بدين ترتيب تنها برنامه هاي درون اين شاخه توسط فرمان exec قابل دسترس خواهند بود.
کد:
safe_mode_include_dir = /usr/local/lib/php/safe-include
safe_mode_exec_dir = /usr/local/lib/php/safe-bin

شما مي توانيد اعمال مربوط به فايل ها را از طريق متغير open_basedir محدود کنيد. آدرس نسبت داده شده به اين متغير به عنوان ريشه اصلي (root) براي اعمال مربوط به فايل ها به کار مي رود. وقتي که اين متغير مقدار مي گيرد فايلهايي که در ساختار درختي اين ريشه نباشند براي PHP غير قابل دسترس خواهند بود. اين روش مناسبي براي محدود کردن کاربران يک سيستم اشتراکي مي باشد تا آنها تنها به آدرسهاي مربوط به خودشان دسترسي داشته باشند.
کد:
open_basedir = /home/web/

متغير max_execution_time تعيين ميکند که PHP حداکثر چند ثانيه منتظر پايان يافتن يک کد باشد قبل از آنکه به اجبار آن را خاتمه دهد. وقتي کد شما گرفتار حلقه هاي بينهايت ميشود اين متغير بکار مي آيد.اگر چه ممکن است اين موضوع گاهي مزاحمت ايجاد کند مثلا زماني که کد نوشته شده نياز به انجام اعمال زمانبري دارد، مثلا upload کردن يک فايل حجيم. در اين مواقع بايد مواظب باشيد که اين مقدار را افزايش دهيد تا مانع آن شويد که PHP اجراي کد شما را در وسط يک کار مهم خاتمه دهد.
کد:
max_execution_time = 90


تنظيمات مربوط به upload فايل ها و متغير هاي فرمها
اگر پيکربندي هاي امنيتي که تاکنون ذکر شد کافي نيست باز هم مي توانيد با غير فعال کردن قابليت upload فايل از طريق متغير file_uploads، يا با محدود کردن حداکثر حجم قابل upload از طريق متغير upload_max_filesize سيستم خود را از اين هم امن تر کنيد. اغلب تمايل خواهيد داشت که فضاي کوچکي را براي upload فايلها اختصاص دهيد مگر اينکه برنامه اي داشته باشيد که قرار باشد فايل هايي نظير يک گالري عکس يا يک FTP Service را پذيرا باشد.
کد:
file_uploads = On
upload_max_filesize = 2M

اگر تمايلي به upload کردن فايلها نداريد اما از تعداد زيادي فرم در صفحات PHP تان استفاده ميکنيد، 2 متغير ديگر وجود دارد که بايد برايتان جالب باشد. اول متغير register_globals، علت بيشترين سردردهاي برنامه نويسان با سابقهPHP در PHP 3.x اين متغير به طور پيش فرض فعال بود (on) که موجب ميشد وقتي يک فرم submit مي شد متغيرهاي آن بطور اتوماتيک به متغيرهاي PHP تبديل شوند.
مسايل امنيتي موجب شد که در PHP 4.x اين متغير بطور پيش فرض غير فعال باشد. (off). در نتيجه متغيرهاي فرم تنها به کمک آرايه هاي ويژه $_GET و $_POST قابل دسترس باشند. اين امر خيلي از کدهاي نوشته شده با PHP 3.x را با مشکل مواجه ساخت. مثلا مقداري که در يک فيلد <input type=”text” name=”email”> وارد شده بود در PHP 3.x با $email قابل دسترس بود در حالي که در PHP 4.x با $_POST يا $_GET[email] ميتوان به آن رجوع کرد.
ميتوانيد اين متغير را غير فعال کنيد (off) تا امنيت بيشتري را در برابر حملاتي که از طريق فرمها صورت مي گيرند برقرار کنيد. به منظور سازگاري با کدهاي نوشته شده با PHP 3.x آن را فعال کنيد:
[code]register_globals = on[/code]

متغير ديگري که به کار با فرم ها مربوط ميشود post_max_size است که کنترل مي کند حداکثر چه حجم داده اي توسط متد POST يک فرم پذيرفته شود. به نظر نمي آيد که زماني لازم شود اين مقدار را از 8 MB افزايش دهيد. در عوض احتمال دارد بخواهيد آن را به يک مقدار واقعي تر تغيير دهيد. به هر حال اگر قصد داريد از امکانات upload فايل در PHP استفاده کنيد اين مقدار را بيشتر از مقدار متغير upload_max_size قرار دهيد.
[code]post_max_size = 8M[/code]

يک متغير جديد هم در PHP 5 معرفي شده است: max_input_time. که حداکثر زمان بر حسب ثانيه که عمل دريافت داده هاي ورودي از طريق POST ،GET و PUT مي تواند طول بکشد را مشخص مي کند. اگر برنامه شما تحت يک اتصال کند اجرا مي شود بهتر است اين مقدار را افزايش دهيد تا به برنامه اجازه دهيد مدت بيشتري را به دريافت داده هاي ورودي اختصاص دهد.
[code]max_input_time = 90[/code]


[b]افزايش کارآيي[/b]
هنوز مقادير ديگري هم وجود دارد که با دستکاري آنها مي توانيد کارايي مفسر PHP را بالا ببريد. به منظور جلوگيري از اجراي کدهايي که ممکن است تمام حافظه موجود سيستم را اشغال کنند، PHP به شما اجازه مي دهد که براي استفاده از حافظه محدوديتي معين کنيد. اين کار از طريق متغير memory_limit قابل انجام است که حداکثر ميزان حافظه قابل استفاده توسط يک برنامه واحد را مشخص مي کند.
[code]memory_limit = 8M[/code]

مقدار متغير memory_limit اغلب بايد از مقدار متغير post_max_size بيشتر باشد.
مساله ديگري که با دانستن آن مي توانيد کارايي را افزايش دهيد غير فعال کردن متغيرهاي $argc و $argv است که تعداد و محتواي آرگومان هاي خط فرمان که به يک برنامه ارسال شده اند، را مشخص مي کنند.
[code]register_argc_argv = false[/code]

همينطور غير فعال کردن آرايه هاي $HTTP_GET_VARS , $HTTP_POST_VARS . چرا که به احتمال زياد در دنياي جديد $_GET , $_POST ديگر نيازي به آنها نيست. غير فعال کردن اين اجزا باعث بهبود کارآيي مي شود البته فقط در PHP 5 و از طريق متغيرregister_long_arrays قابل انجام است.
[code]register_long_arrays = false[/code]


[b]تابع ini_set[/b]
و در آخر نکاتي در مورد تابع ini_set. در حالي کهPHP تمام تنظيمات اش را در هنگام بالا آمدن، از فايل php.ini مي خواند، اين اجازه را به شما مي دهد که اين تنظيمات را به کمک تابع جالب ini_set و در برنامه خود انجام دهيد. البته اين تغييرات فقط براي همان برنامه اي که در آن از تابع ini_set استفاده کرده ايد اعمال مي شوند .اين تابع 2 آرگومان مي گيرد: نام متغير پيکربندي اي که مي خواهيد مقدارش را تغيير دهيد و مقدار جديد آن. اين هم يک مثال که حداکثر زمان اجراي مجاز براي برنامه اي که اين کد در داخل آن نوشته شده است را افزايش مي دهد.
[code]<?php

ini_set('max_execution_time', 600);

// more code

?>[/code]
باز هم يادآوري مي شود که اين تنظيمات در داخل هر برنامه اي که نوشته شود فقط همان برنامه را تحت الشعاع قرار مي دهد. وقتي که برنامه خاتمه پيدا کند مقدار متغير به طور اتوماتيک به مقدار اوليه تغيير خواهد کرد.

اگر برنامه هايPHP شما بر روي يک سرور مشترک (Shared Server) اجرا مي شوند احتمالا شما دسترسي به فايل پيکربندي php.ini نخواهيد داشت. در اين موارد تابع ini_set کمک شاياني مي کند. چرا که اجازه مي دهد تنظيمات مورد نظرتان را براي برنامه هاي خودتان اعمال کنيد.
 

جدیدترین ارسال ها

بالا