WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World
Execute an external program and display the output

system

(PHP 4, PHP 5)

systemExecute an external program and display the output

Description

string system ( string $command [, int &$return_var ] )

system() is just like the C version of the function in that it executes the given command and outputs the result.

The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.

If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

Parameters

command

The command that will be executed.

return_var

If the return_var argument is present, then the return status of the executed command will be written to this variable.

Return Values

Returns the last line of the command output on success, and FALSE on failure.

Examples

Example #1 system() example

<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line system('ls'$retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' 
$last_line '
<hr />Return value: ' 
$retval;
?>

Notes

Warning

When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.

Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.

Warning

With safe mode enabled, the command string is escaped with escapeshellcmd(). Thus, echo y | echo x becomes echo y \| echo x.

See Also


Simple Time Clock System
Categories : PHP, MySQL, Databases, Complete Programs
Complete upload scripts to upload three files and you can extend it. Upload files system
Categories : PHP, Filesystem
A script using Windows Scripting Host 1.0 can be executed on a scheduled basis from Windows NT's scheduler. This is useful for system administrators to run unattended tasks
Categories : WinNT



Dynamic Image Authentication System in Signup Pages (CAPTCHA)
Categories : PHP, Security, GD image library
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
PHP5 Security System
Categories : PHP, PHP Classes, Security
free, search engine, indexing, system, information, web, ftp, http, free, software, cgi, php, MySQL, database, php3, FreeBSD, Linux, Unix, UdmSearch
Categories : MySQL, Complete Programs, PHP, Databases, Search
Education Center is a set of PHP-scripts to administer a corporate education and examination system via Internet/intranet written in PHP for MySQL.
Categories : PHP, Databases, MySQL, Complete Programs
How to get the exit code of a function ran by system().
Categories : PHP
Flexphpsite - a Content Management System (CMS) in PHP and MySQL
Categories : Content Management, Complete Programs, Databases, Multimedia, PHP
who.php3 - prints a summary of the current activity on the system, including what each user is doing and where they are logged if from. PHP3 functions: exec, ereg System: IRIX 6.3
Categories : Complete Programs, PHP
PHP Mysql Paging System
Categories : PHP, MySQL, Databases
Creates an ID that is some what sequential but still is "a little" difficult to guess, but also is descriptive to the system.
Categories : PHP, MySQL
How to implement a session tracking system.
Categories : PHP, Sessions, Variables