Reputation: 2298
I would like the version of a web server (Nginx, MySQL, MariaDB, ...) in PHP.
I know the function for Apache: apache_get_version()
.
There are many phpinfo()
which returns all values but how to exploit?
You would have an idea or it is not possible for the moment?
Upvotes: 5
Views: 4911
Reputation: 3758
To query the version of MySQL and/or MariaDB in PHP, you could use mysqli_get_server_info() or (if you are still using the older mysql API which was deprecated in PHP 5.5.0 and removed in PHP 7.0.0) mysql_get_server_info(). The PDO API has no similar function or class for that purpose, but in that case you could just use the result of the SQL query
SELECT VERSION();
It returns something like 5.5.50-0+deb7u2
. Here's a quick example:
<?php
$user = 'username_here';
$pass = 'your_db_password';
// create DB connection
$dbh = new PDO('mysql:host=localhost;dbname=mysql', $user, $pass);
$stmt = $dbh->query('SELECT VERSION();');
//fetch first column of first result row and print it out
echo $stmt->fetchColumn();
//unset PDOStatement and PDO to close DB connection
unset($stmt);
unset($dbh);
?>
Upvotes: 0
Reputation: 926
The other answers mention different methods on how to get the web server and database versions, however there is a function which will get the operating system itself.
// Gets the "System" row shown at the top of the `phpinfo()` table.
$system = php_uname( $mode = 'a' );
You can specify the mode to select different components. By default it'll display all of the components, separated by spaces and in the following order:
You can view more information about the php_uname
function here.
Upvotes: 1
Reputation:
You can retrieve the web server's version by using the $_SERVER superglobal, more specifically by using:
$_SERVER['SERVER_SIGNATURE']
As per PHPs Documentation:
SERVER_SIGNATURE
String containing the server version and virtual host name which are added to server-generated pages, if enabled.
You can find more info on the official PHP Documentation site: http://php.net/manual/en/reserved.variables.server.php
Upvotes: 2
Reputation: 24406
A simple shell_exec
would do the trick (assuming you're on a unix based server). Just don't put any user data into the command, and be aware that this approach may not work in shared hosting environments:
$nginxVersion = shell_exec('nginx -v 2>&1');
$mysqlVersion = shell_exec('mysql --version');
Note that nginx sends version output to stderr, so you need to pipe it to stdout to capture it.
Upvotes: 3
Reputation: 199
Address the $_SERVER super-global http://php.net/manual/en/reserved.variables.server.php
I believe the setting you want is:
echo $_SERVER['SERVER_NAME'];
Upvotes: 1