Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

useful only in those rare instances when environment variables change after a script
begins executing. If you need to set the value of an environment variable, use putenv.


<?
print(getenv("PATH"));
?>


string passthru(string command, integer return)


The passthru function is similar to exec and system. The command argument is executed
as if you typed it in a command shell. If you provide the optional return argument, it
will be set with the return value of the command. All output will be returned by the
passthru function and sent to the browser. The output will be sent as binary data. This is
useful in situations where you need to execute a shell command that creates some binary
file, such as an image. See Chapter 17, "Database Integration," for an application of
this.


It is very dangerous to put any user-supplied information inside the command argument.
Users may pass values in form fields that allow them to execute their own commands on
your Web server. If you must allow this, pass the information through the
escapeshellcmd function first.


putenv(string variable)


The putenv function sets the value of an environment variable. You must use syntax
similar to that used by a command shell, as shown in the example below. To get the value
of an environment variable, use getenv, or use phpinfo to dump all environment
variables.


<?
putenv("PATH=/local/bin;.");
?>


string system(string command, integer return)


The system function behaves identically to C's system function. It executes the command
argument, sends the output to the browser, and returns the last line of output. If the
return argument is provided, it is set with the return value of the command. If you do
not wish for the output to be sent to the browser, use the exec function.


It is very dangerous to put any user-supplied information inside the command argument.
Users may pass values in form fields that allow them to execute their own commands on

Free download pdf