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

(singke) #1

open string SavePath, string SessionName
close none read string Variable


write string Variable, Value
destroy none
garbage integer MaximumLifetime


Shell Commands


This section describes functions that interact with the command shell in some way. Some
of them execute other programs, and two of them read or write to environment variables.


string exec(string command, array output, integer return)


The exec function attempts to execute the command argument as if you had typed it in
command shell. Nothing is echoed to the browser, but the last line of output from the
execution is returned. If the optional output argument is supplied, each line of output will
be added to the output argument as an array element. If the optional return argument is
supplied, the variable is set to the return value of the command.


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 execute a command based on user input, pass the
information through the escape-shellcmd function, defined in Chapter 9.


Compare this function to passthru and system.


<?
// get directory list for the root of C drive
$LastLine = exec("dir C:\ quote>, $AllOutput, $ReturnValue);


print("Last Line: $LastLine BR>\n");


print("All Output:BR>\n");
for($index = 0; $index count($AllOutput); $index++)
{
print("$AllOutput[$index] BR>\n");
}
print("BR>BR>\n");


print("Return Value: $ReturnValueBR>\n");
?>


string getenv(string variable)


The getenv function returns the value of the given environment variable or false if there
is an error. PHP converts all environment variables into PHP variables, so this function is

Free download pdf