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: 3752 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>
|
|
|
Back to top |
|
|
JMMotyer -
Joined: 06 Jul 2005 Posts: 69 Location: Burlington (Toronto-ish), Ontario, Canada
|
Posted: Fri Mar 24, 2023 5:15 pm Post subject: |
|
|
Hello, folks, I realize that this thread is 16 years old, but...
When I use the code above from TRUSTAbyss, what is produced is:
Quote: | Array ( [version] => 2.16.4 [type] => X2 [os] => Win32 [libversion] => 2.16.4 ) |
How can I change the code slightly, in order to be able to have a variable for the [version] number, and another variable for the [os]?
I wish to be able to use something like this on my site:
Code: | echo $abyss_version['version']
echo $abyss_version['os']
|
Thank you in advance.
Regards,
John |
|
Back to top |
|
|
admin Site Admin
Joined: 03 Mar 2002 Posts: 1319
|
Posted: Sat May 06, 2023 4:26 pm Post subject: |
|
|
JMMotyer wrote: |
Code: |
/* Paste get_abyss_info() function definition here */
$abyss_version = get_abyss_info($_SERVER["SERVER_SOFTWARE"]);
echo $abyss_version['version'];
echo $abyss_version['os'];
|
|
_________________ Follow @abyssws on Twitter
Subscribe to our newsletter
_________________
Forum Administrator
Aprelium - https://aprelium.com |
|
Back to top |
|
|
JMMotyer -
Joined: 06 Jul 2005 Posts: 69 Location: Burlington (Toronto-ish), Ontario, Canada
|
Posted: Sat May 06, 2023 9:02 pm Post subject: |
|
|
That works perfectly. Thank you, folks, for your support & solution.
Regards,
John |
|
Back to top |
|
|
DyktaT -
Joined: 08 Aug 2023 Posts: 1 Location: Warsaw
|
Posted: Tue Aug 08, 2023 4:40 pm Post subject: |
|
|
admin wrote: | JMMotyer wrote: |
Code: |
/* Paste get_abyss_info() function definition here */
$abyss_version = get_abyss_info($_SERVER["SERVER_SOFTWARE"]);
echo $abyss_version['version'];
echo $abyss_version['os'];
|
|
|
Hi,
I just registered in I have also a small problem, the problem is that somehow it doesn't show correct version, how it is possible? _________________ Proud Head Redactor of sprytne.pl.
Father of a 2 children.
Interested in Technology, Finances and good musics. |
|
Back to top |
|
|
admin Site Admin
Joined: 03 Mar 2002 Posts: 1319
|
Posted: Wed Aug 09, 2023 8:59 pm Post subject: |
|
|
DyktaT wrote: | I just registered in I have also a small problem, the problem is that somehow it doesn't show correct version, how it is possible? |
What does it show instead of the full version? What is the exact code you're using? _________________ Follow @abyssws on Twitter
Subscribe to our newsletter
_________________
Forum Administrator
Aprelium - https://aprelium.com |
|
Back to top |
|
|
|