- putenv
- Список параметров
- Возвращаемые значения
- Примеры
- Смотрите также
- User Contributed Notes 8 notes
- PHP Environment Variables Windows 10/11 Xampp
- How to Set PHP Path in Environment Variables Windows 11/10 Xampp
- Step 1 – Open Windows 11/10 Environment Setting
- Step 2 – Environment Setting
- Step 3 – Edit System Environment Variable Path
- Step 4 – Add PHP Xampp Path
- Step 5 – Restart Windows 10
- Step 6 – Open Command Prompt and Check PHP Version
- Set Environment Variable in PHP
- Steps on How to Set the Environment Variable for PHP in Windows
- Initial Setup to Set the Environment Variable for PHP in Windows
- Launch System Settings to Set the Environment Variable for PHP in Windows
- Launch Advanced System Settings to Set the Environment Variable for PHP in Windows
- Launch the Environment Variables Dialog Window to Set the Environment Variable for PHP in Windows
- Create a New User Variable to Set the Environment Variable for PHP in Windows
- Test PHP From the Command Line in Windows
- Related Article — PHP Variable
putenv
Добавляет assignment в переменные окружения сервера. Переменная будет существовать только на время выполнения текущего запроса. По его завершении переменная вернётся в изначальное состояние.
Список параметров
Возвращаемые значения
Возвращает true в случае успешного выполнения или false в случае возникновения ошибки.
Примеры
Пример #1 Установка значения переменной среды
Смотрите также
- getenv() — Получает значение одной или всех переменных окружения
- apache_setenv() — Устанавливает переменную subprocess_env Apache
User Contributed Notes 8 notes
putenv/getenv, $_ENV, and phpinfo(INFO_ENVIRONMENT) are three completely distinct environment stores. doing putenv(«x=y») does not affect $_ENV; but also doing $_ENV[«x»]=»y» likewise does not affect getenv(«x»). And neither affect what is returned in phpinfo().
Assuming the USER environment variable is defined as «dave» before running the following:
print «env is: » . $_ENV [ «USER» ]. «\n» ;
print «(doing: putenv fred)\n» ;
putenv ( «USER=fred» );
print «env is: » . $_ENV [ «USER» ]. «\n» ;
print «getenv is: » . getenv ( «USER» ). «\n» ;
print «(doing: set _env barney)\n» ;
$_ENV [ «USER» ]= «barney» ;
print «getenv is: » . getenv ( «USER» ). «\n» ;
print «env is: » . $_ENV [ «USER» ]. «\n» ;
phpinfo ( INFO_ENVIRONMENT );
?>
prints:
env is: dave
(doing: putenv fred)
env is: dave
getenv is: fred
(doing: set _env barney)
getenv is: fred
env is: barney
phpinfo()
Variable => Value
.
USER => dave
.
The other problem with the code from av01 at bugfix dot cc is that
the behaviour is as per the comments here, not there:
putenv ( ‘MYVAR=’ ); // set MYVAR to an empty value. It is in the environment
putenv ( ‘MYVAR’ ); // unset MYVAR. It is removed from the environment
?>
White spaces are allowed in environment variable names so :
putenv ( ‘U =33’ );
?>
Is not equivalent to
Environment variables are part of the underlying operating system’s
way of doing things, and are used to pass information between a parent
process and its child, as well as to affect the way some internal
functions behave. They should not be regarded as ordinary PHP
variables.
A primary purpose of setting environment variables in a PHP script is
so that they are available to processes invoked by that script using
e.g. the system() function, and it’s unlikely that they would need to
be changed for other reasons.
For example, if a particular system command required a special value
of the environment variable LD_LIBRARY_PATH to execute successfully,
then the following code might be used on a *NIX system:
$saved = getenv ( «LD_LIBRARY_PATH» ); // save old value
$newld = «/extra/library/dir:/another/path/to/lib» ; // extra paths to add
if ( $saved ) < $newld .= ": $saved " ; >// append old paths if any
putenv ( «LD_LIBRARY_PATH= $newld » ); // set new value
system ( «mycommand -with args» ); // do system command;
// mycommand is loaded using
// libs in the new path list
putenv ( «LD_LIBRARY_PATH= $saved » ); // restore old value
?>
It will usually be appropriate to restore the old value after use;
LD_LIBRARY_PATH is a particularly good example of a variable which it
is important to restore immediately, as it is used by internal
functions.
If php.ini configuration allows, the values of environment variables
are made available as PHP global variables on entry to a script, but
these global variables are merely copies and do not track the actual
environment variables once the script is entered. Changing
$REMOTE_ADDR (or even $HTTP_ENV_VARS[«REMOTE_ADDR»]) should not be
expected to affect the actual environment variable; this is why
putenv() is needed.
Finally, do not rely on environment variables maintaining the same
value from one script invocation to the next, especially if you have
used putenv(). The result depends on many factors, such as CGI vs
apache module, and the exact way in which the environment is
manipulated before entering the script.
It’s the putenv() type of environment variables that get passed to a child process executed via exec().
If you need to delete an existing environment variable so the child process does not see it, use:
That is, leave out both the » note» >
Values of variables with dots in their names are not output when using getenv(), but are still present and can be explicitly queried.
(saw this behaviour using PHP 8.2.4)
// dump explicitely ‘foo.bar’
var_dump ( getenv ( ‘foo.bar’ )); # works, value ‘baz’ is shown
Multiple invocations of putenv() work as expected: the real problem was that some of the putenv() invocations in my script contained typographical errors.
I typed, e.g., putenv( «IMAGE_DATABASE note» >
Great examples for the trivial case that most can figure out directly from the manual, but where is the trivially more complex example describing how to set multiple variables? I tried separating with spaces, commas, semicolons, multiple invocations of setenv, all to no avail. Please try to include trivial extensions to the examples.
- Опции PHP/информационные функции
- assert_options
- assert
- cli_get_process_title
- cli_set_process_title
- dl
- extension_loaded
- gc_collect_cycles
- gc_disable
- gc_enable
- gc_enabled
- gc_mem_caches
- gc_status
- get_cfg_var
- get_current_user
- get_defined_constants
- get_extension_funcs
- get_include_path
- get_included_files
- get_loaded_extensions
- get_required_files
- get_resources
- getenv
- getlastmod
- getmygid
- getmyinode
- getmypid
- getmyuid
- getopt
- getrusage
- ini_alter
- ini_get_all
- ini_get
- ini_parse_quantity
- ini_restore
- ini_set
- memory_get_peak_usage
- memory_get_usage
- memory_reset_peak_usage
- php_ini_loaded_file
- php_ini_scanned_files
- php_sapi_name
- php_uname
- phpcredits
- phpinfo
- phpversion
- putenv
- set_include_path
- set_time_limit
- sys_get_temp_dir
- version_compare
- zend_thread_id
- zend_version
- get_magic_quotes_gpc
- get_magic_quotes_runtime
- restore_include_path
PHP Environment Variables Windows 10/11 Xampp
Set PHP environment variables windows 11/10 xampp; Through this tutorial, you will learn how to set or add PHP environment variables in windows 11/10 xampp.
How to Set PHP Path in Environment Variables Windows 11/10 Xampp
- Step 1 – Open Windows 11/10 Environment Setting
- Step 2 – Edit Environment Setting
- Step 3 – Edit System Environment Variable Path
- Step 4 – Add PHP Path
- Step 5 – Restart Windows 11/10
- Step 6 – Open Command Prompt and Check PHP Version
Step 1 – Open Windows 11/10 Environment Setting
First of all, visit your system bottom search bar and search Environment Variables; as shown below picture:
Step 2 – Environment Setting
Then Click on the environment variable setting; as shown below picture:
Step 3 – Edit System Environment Variable Path
Edit system environment variable path; as shown below picture:
Step 4 – Add PHP Xampp Path
Add/set PHP xampp path in environment setting; as shown below picture:
Note that; we have installed xampp in D directory.
Step 5 – Restart Windows 10
Restart your windows 10 system.
Step 6 – Open Command Prompt and Check PHP Version
Now, open your command prompt and run the following command to check php version:
Set Environment Variable in PHP
This tutorial is an illustrated step-by-step guide on setting up an environment variable for PHP using WAMP on your Windows system. This allows you to use PHP from the command line.
Steps on How to Set the Environment Variable for PHP in Windows
With that said, the following are the steps to set up an environment variable for PHP.
Initial setup
Launch system settings
Launch Advanced system settings
Launch the Environment Variables dialog window
Create a new User variable
Test PHP from the command line
Initial Setup to Set the Environment Variable for PHP in Windows
To follow this tutorial, ensure you have WAMP installed on your system in your C:\ drive. Preferably, the installation folder for WAMP should be c:\wamp64 or c:\wamp32 , depending on your system architecture and the version of WAMP you have installed.
Launch System Settings to Set the Environment Variable for PHP in Windows
You can launch the system settings from the Control Panel or via a shortcut from the Run dialog box; we’ll go with the latter option.
Press the Windows + R key simultaneously on your keyboard; this should bring up the Run dialog box, then type control system and hit Enter or click the OK button.
Launch Advanced System Settings to Set the Environment Variable for PHP in Windows
If you are using an earlier version of Windows, you’ll find the Advanced system settings link on the left side of the System Settings window. However, if you are using a modern version of Windows, it will be on the right side.
Clicking on the Advanced system settings link pops up a dialog window.
Launch the Environment Variables Dialog Window to Set the Environment Variable for PHP in Windows
In the Advanced system settings dialog window, you’ll find a button close to the bottom of the dialog window. Click on the button that reads Environment Variables , as shown in the image below.
When you click on the button, you are presented with another dialog window to manage User variables and System variables in your system.
Create a New User Variable to Set the Environment Variable for PHP in Windows
The dialog window for the Environment Variables has two sections; the first section is for setting the User variables , while the second section is for the System variables . Our interest lies in the first section.
Click on Path in the first section, then press the New button. Another dialog window pops up to create a New User Variable .
Type Path and the variable value in the variable name, click on the button that reads Browse Directory and navigate to the PHP directory in your WAMP installation.
If you installed the latest version of WAMP, you could have multiple versions of PHP installed. If that is the case, navigate to the folder of your preferred version of PHP and click the OK button.
The window to create a New User Variable has the variable name, Path and your PHP installation directory. With that, click the OK button to save, and you are set to use PHP from the command line.
Test PHP From the Command Line in Windows
Launch the command line and type php -v ; this will display the version you’ve set in the system Environment Variables . If you get the PHP version, that means you can use PHP from the command line.
You can also check the PHP installation information, as shown in the image below.
Habdul Hazeez is a technical writer with amazing research skills. He can connect the dots, and make sense of data that are scattered across different media.
Related Article — PHP Variable