View previous topic :: View next topic |
Author |
Message |
rrinc -
Joined: 24 Feb 2006 Posts: 725 Location: Arkansas, USA
|
Posted: Fri Apr 20, 2007 2:30 am Post subject: Abyss Webserver name/version in PHP |
|
|
Lets say you need or want to display the version number of Abyss. This is actually very easy to do. The basic idea is to get $_SERVER['SERVER_SOFTWARE'] and format it. There's a few ways you can format it to look good and/or be useful.
First of all, this is what $_SERVER['SERVER_SOFTWARE'] looks like on Abyss Webserver X1 v2.4.0.3: Code: | Abyss/2.4.0.3-X1-Win32 AbyssLib/2.4.0.3 |
That's long and not very useful in that form, we can separate stuff out of it and just grab parts of it.
One thing we can do is use substr() and cut off everything but the first 13 characters, which we would do with the following PHP code: Code: | echo substr($_SERVER['SERVER_SOFTWARE'], 0, 13); |
That would produce:
We could take that even farther and do something like this:
Code: | echo str_replace('/' ,' Web Server ' , substr($_SERVER['SERVER_SOFTWARE'], 0, 13)); | Which would produce: Code: | Abyss Web Server 2.4.0.3 | What we just did was cut the variable down to 13 characters then replaced the "/" with " Web Server ". We could stick the words "Powered by" in front of that and make a nice footer for your website.
If you just need the version number, that can be achieved with this code:
Code: | echo str_replace('Abyss/' ,'' , substr($_SERVER['SERVER_SOFTWARE'], 0, 13)); | In that code, we're just replacing "Abyss/" with nothing, which produces:
There's my little tutorial. Just ask if you need help or an explanation.
Its possible that this code could stop working correctly if Aprelium gives Abyss longer version numbers. _________________ -Blake | New Server :D
SaveTheInternet
Soy hispanohablante. Puedes contactarme por mensajes privados. |
|
Back to top |
|
 |
loloyd -
Joined: 03 Mar 2006 Posts: 435 Location: Philippines
|
Posted: Fri Apr 20, 2007 3:22 am Post subject: |
|
|
The reliability of this route may break down if Abyss has various ways and means of writing its version number across different versions. To wit:
1. 2.4.0.3
2. 2.4
3. 2.3.2
As you can see, using a fixed index position for substr may not be of use to those with different versions.
If you look at the resultant string closely, you will find that Abyss uses delimiters for describing its software version.
Code: | Abyss/<version>-<package>-<OS platform><white space>AbyssLib/<library version> |
It would be a good idea to work with these delimiters instead in order to get to the version you are looking for. So you have to "explode" the string into an array delimited first by whitespace. Then "explode" the resultant array[0] by "/". Then "explode" the next resultant array[1] by "-". Then grab the last resultant array[0] - which will be the Abyss version number no matter what its length is.
Parsing strings is a personal area of interest of mine :-D. _________________
http://home.loloyd.com/ is online if the logo graphic at left is showing. |
|
Back to top |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3740 Location: USA, GA
|
Posted: Fri Apr 20, 2007 12:05 pm Post subject: |
|
|
You should use a Regular Expression for that. I created a rather simple function using a Regex to capture each part of the Server header string. Enjoy!
Aprelium showed me how to do this a while back.
Code: | <pre>
<?php
/**
* Function: (Array) get_abyss_info()
* Created by: Josh (TRUSTAbyss)
*
* Provided by: trustabyss.com
*/
function get_abyss_info($string)
{
$array = array();
if (preg_match("/^Abyss\/(.+)-(.+)-(.+)\sAbyssLib\/(.+)$/", $string, $match))
{
$array["version"] = $match[1];
$array["type"] = $match[2];
$array["os"] = $match[3];
$array["libversion"] = $match[4];
return $array;
}
else
{
return false;
}
}
// We use the print_r function to show the structure of the array.
print_r(get_abyss_info($_SERVER["SERVER_SOFTWARE"]));
?>
</pre>
|
_________________ Computer Programmer & Networking Specialist |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|