PDA

View Full Version : مقاله: ایجاد تغییرات در php.ini (انگلیسی)



oxygenws
دوشنبه 05 مرداد 1383, 19:10 عصر
در این تاپیک و در دو بخش مقاله ای از سایت builder.com را می چسبانم که توضیحات جالب و کاملی از انواع ایجاد تغییرات عمومی در فایل php.ini نوشته.

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

ممنون می شم دوستانی که دوست دارند همکاری کنند، این مقاله رو به فارسی برگردونند و در همین جا بفرستند. مقالهء فارسی ایشون در چندین سایت با نام ایشون ثبت خواهد شد.

oxygenws
دوشنبه 05 مرداد 1383, 19:13 عصر
قسمت اول:


***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
دوشنبه 05 مرداد 1383, 19:22 عصر
قسمت دوم:


***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 = me@localhost.com

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.

رها
دوشنبه 02 شهریور 1383, 07:06 صبح
سلام.
ترجمه قسمت اول این مقاله آماده شد. :wink:
به زودی ترجمه قسمت دوم رو هم در اینجا قرار می دهم.الته برای اینکه یه خورده طولانیه وبرای راحتی دوستان جهت ذخیره کردن آن به صورت زیپ شده به انتهای همین صفحه چسباندم.
البته خوشحال می شم اگه توی ترجمه موردی هست دوستان عزیز بهم بگن.
خوب تا قسمت دوم خدانگهدار

oxygenws
دوشنبه 02 شهریور 1383, 13:34 عصر
شدیدا سپاسگذارم :) :flower:

oxygenws
چهارشنبه 04 شهریور 1383, 10:59 صبح
سپاسگذارم، هر جفت مقالات رومطالعه، ویرایش و در یک مجموعه با اسم هر دوی شما (و احتمالا آدرس سایت و/یا ایمیل) منتشر می کنم.
موفق باشید، امید

MFCGalaxy
چهارشنبه 04 شهریور 1383, 11:23 صبح
از هر سه س شما دوستان بسایر بسیار ممنون .
خیلی مفید بود . خدا وقتتون بده !! ( یعنی وقت بده که باز هم از این چیزها آماده کنین !! )

رها
چهارشنبه 04 شهریور 1383, 13:43 عصر
از آقا فرشاد بابت ترجمه قسمت دوم بینهایت تشکر می کنم. :wink:
امیدوارم که بازهم بتونیم ازاین نمونه کارها انجام بدیم.
البته از آقا امید هم باید تشکر ویژه کرد.

مرسی از همگی..... :تشویق:

oxygenws
چهارشنبه 04 شهریور 1383, 20:31 عصر
مترجمان:
فرشاد پایدار
farshadcdeb@yahoo.com
جابر صادقی
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 = me@localhost.com
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[email] یا $_GET[email] میتوان به آن رجوع کرد.
میتوانید این متغیر را غیر فعال کنید (off) تا امنیت بیشتری را در برابر حملاتی که از طریق فرمها صورت می گیرند برقرار کنید. به منظور سازگاری با کدهای نوشته شده با PHP 3.x آن را فعال کنید:

register_globals = on

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

post_max_size = 8M

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

max_input_time = 90


افزایش کارآیی
هنوز مقادیر دیگری هم وجود دارد که با دستکاری آنها می توانید کارایی مفسر PHP را بالا ببرید. به منظور جلوگیری از اجرای کدهایی که ممکن است تمام حافظه موجود سیستم را اشغال کنند، PHP به شما اجازه می دهد که برای استفاده از حافظه محدودیتی معین کنید. این کار از طریق متغیر memory_limit قابل انجام است که حداکثر میزان حافظه قابل استفاده توسط یک برنامه واحد را مشخص می کند.

memory_limit = 8M

مقدار متغیر memory_limit اغلب باید از مقدار متغیر post_max_size بیشتر باشد.
مساله دیگری که با دانستن آن می توانید کارایی را افزایش دهید غیر فعال کردن متغیرهای $argc و $argv است که تعداد و محتوای آرگومان های خط فرمان که به یک برنامه ارسال شده اند، را مشخص می کنند.

register_argc_argv = false

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

register_long_arrays = false


تابع ini_set
و در آخر نکاتی در مورد تابع ini_set. در حالی کهPHP تمام تنظیمات اش را در هنگام بالا آمدن، از فایل php.ini می خواند، این اجازه را به شما می دهد که این تنظیمات را به کمک تابع جالب ini_set و در برنامه خود انجام دهید. البته این تغییرات فقط برای همان برنامه ای که در آن از تابع ini_set استفاده کرده اید اعمال می شوند .این تابع 2 آرگومان می گیرد: نام متغیر پیکربندی ای که می خواهید مقدارش را تغییر دهید و مقدار جدید آن. این هم یک مثال که حداکثر زمان اجرای مجاز برای برنامه ای که این کد در داخل آن نوشته شده است را افزایش می دهد.

<?php

ini_set('max_execution_time', 600);

// more code

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

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

mghomeishy2010
یک شنبه 20 بهمن 1387, 12:58 عصر
من میخوام INP رو نصب کنم روی هاستم
با register_globals مشکل دارم، توی برنامه ی install.php از این کد استفاده کردم ولی باز هم همین پیغام خطا رو داد.

Mikili
سه شنبه 19 مرداد 1389, 22:28 عصر
سلام دوستان
چرا روی چیزایی کار میکنید که فارسیش قبلا بوده ؟؟؟ ثابت هایی هست که اصلا روش کار نمیشه و مهمه
ممنون میشم اونا رو ترجمه کنید
موفق باشید