PHP preg_match hostname and domain from FQDN

How to get the hostname and the domain name from FQDN in PHP

This sound easy right? So easy that you would think it would be all over the internet as an example on how to parse host names from domain names. Wrong…. I spent a hour one day looking everywhere and all I found was parsing a URL. Well my needs go deeper I need to do a

How to get the hostname and the domain name from FQDN in PHP

This sound easy right? So easy that you would think it would be all over the internet as an example on how to parse host names from domain names. Wrong…. I spent a hour one day looking everywhere and all I found was parsing a URL. Well my needs go deeper I need to do a quick split of host name from domain name not matter how long or nested the domain names were.

There are a bunch of places that give you the same old PHP preg_match examples as found on www.php.net,   “How to parse the domain name from a URL.”

But lets say I want both the host name and the domain name? If you know anything about FQDN then you know that up to the first “.” is host name and everything else is sub domain, domain and root.

Sometimes your going to have a FQDN that = myname.mysub.mysecondsub.mydomain.root

You want to get “myname” & “mysub.mysecondsub.mydomain .root”

So here is how we do it…


//if host needs to be striped from a URL
preg_match('@^(?:http://)?([^/]+)@i', "http://barfly.beaners.bobbers.mybalistics.net/index.html", $matches);
$host = $matches[1];

//else make $host your FQDN and skip the above segment
preg_match("/^(.*?)\.(.*)/", $host, $rest);
echo "My name is" .$rest[1]. "
";
echo "My domain is" .$rest[2]. "
";

I hope this helps someone out there spending hours looking for the right expression.

PHP Pagination with timestamp / timeline display

Pagination with a timestamp as the center value

We provide a way to scroll page to page of data and show the time stamp of when the data was collected as part of the page navigations.

Here we setup the first query and findout how many pages we have.

$sql = “SELECT COUNT(*) FROM table where name = ‘” . $name . “‘ and type = ‘”

Pagination with a timestamp as the center value

We provide a way to scroll page to page of data and show the time stamp of when the data was collected as part of the page navigations.

Here we setup the first query and findout how many pages we have.


$sql = "SELECT COUNT(*) FROM table where name = '" . $name . "' and type = '" . $type . "'";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 1;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;

Now we need to make the second query for the actual data so we can place our scroll links and then display our data.


$sql = "SELECT * FROM table where name = '" . $name . "' and type = '" . $type . "' ORDER BY data_time DESC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
while($row = mysql_fetch_array($result)){
$data = $row['data'];
$data_time = $row['data_time']; // expected in epoch
}
$range = 8;
echo "Reported data";
if ($currentpage > 1) {
echo " << ";
$prevpage = $currentpage - 1;
echo " < ";
}

for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [";
$rectime = date(DATE_RFC822, $data_time);
echo $rectime;
echo "]
";
} else {
echo " $x ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " > ";
echo " >> ";
}

echo "


";
echo $data;
echo "";

 

You should have a database that use epoch time as its time field then set $data_time to that field. You will get a nice output with links to pages forward and previous and the time stamp in local time in the center as the current page you are on. Great for scrolling throught time dlimited data in a time line.

AlertOnFailure Runs Remote Desktop Proxy Service

AlertOnFailure is working on a Remote Desktop feature in their Free computer system monitoring services. The service is new and they expect to have integrate more deeply in AOF hosted services in the near future.  Currently the services provides the ability to connect 2 Microsoft Windows desktops together allowing a support tech, systems admin or friendly and knowledgeable

AlertOnFailure is working on a Remote Desktop feature in their Free computer system monitoring services. The service is new and they expect to have integrate more deeply in AOF hosted services in the near future.  Currently the services provides the ability to connect 2 Microsoft Windows desktops together allowing a support tech, systems admin or friendly and knowledgeable user the ability to see and control another Desktop system.

See their new tool at: desktop.alertonfailure.com

website:  www.alertonfailure.com

GraphMyWebsite – Providing Free Website Monitoring

Free website monitoringGraphMyWebsite (www.graphmywebsite.com)  is a free website monitoring service provided by the good people here at Squidworks.

This service monitors websites for outages and graphs their performance. If your looking for a easy website uptime monitor and alerting service GMW is for you. Get email notifications when failing services are detected.

GMW provides all

Free website monitoringGraphMyWebsite (www.graphmywebsite.com)  is a free website monitoring service provided by the good people here at Squidworks.

This service monitors websites for outages and graphs their performance. If your looking for a easy website uptime monitor and alerting service GMW is for you. Get email notifications when failing services are detected.

GMW provides all services for free and there is no catch. Just enjoy the tools. They also do IP GeoLocation tracking, DNS Slueth along with an array of other network test. Go give them a try.

www.graphmywebsite.com

New WebSite Development – www.floridarnr.com

Florida Society of Registered Nurses Retired  website development was completed this week located at www.floridarnr.com .

This site was developed using Wordpress and our own custom template developed for FSRNR. All logos and design aspects were completed as per the customers requests and site level training for the staff has commenced

Florida Society of Registered Nurses Retired  website development was completed this week located at www.floridarnr.com .

This site was developed using WordPress and our own custom template developed for FSRNR. All logos and design aspects were completed as per the customers requests and site level training for the staff has commenced.

HOW-to: PHP Multiple Select List Box quick and easy..

Sometimes you find that it requires a little looping to get data from a form when using PHP and Multiple select list boxes. Here is a quick and easy way to loop through select data sent from a form in html. We also show you here how to use a Array of data to create the options. This is great if your doing a database query and need to use

Sometimes you find that it requires a little looping to get data from a form when using PHP and Mulitple select list boxes. Here is a quick and easy way to loop through select data sent from a form in html. We also show you here how to use a Array of data to create the options. This is great if your doing a database query and need to use that data in select box.

HTML :

select id="select[]" multiple="multiple" name="select[]" size="10"

option value=" . $listID . ">" .$listItem. ""; } /option /select

input id="button" name="button" type="submit" value="Submit" /

if (isset($_POST['select'])) {
$az = $_POST['select'];
foreach ($az as $a)
{
echo $a;
}
}

 

ELGG Plugin:AdBrite -> BritePics patch for TidyPics

As part of Squidworks community involvement in Open source software we have added another code enhancement to the ELGG community.

This patch adds the BritePics Advertising feature to TidyPics plugin for ELGG.
Now when your images are viewed in full size your Adbrite account will post a quick ad over image. It also helps protect your images as the images is now wrapped in a flash player

As part of Squidworks community involvement in Open source software we have added another code enhancement to the ELGG community.

This patch adds the BritePics Advertising feature to TidyPics plugin for ELGG.
Now when your images are viewed in full size your Adbrite account will post a quick ad over image. It also helps protect your images as the images is now wrapped in a flash player

Just copy the image.php file to /mod/tidypics/view/default/object/

remember to backup old file before you over write it.

ELGG->BritePicPlugin

www.alertonfailure.com Free BBDisplay and BBpager Monitor Service under development

Alert On Failure

  

 The Engineers at Squidworks are building another free web services site. AlertOnFailure.com is the first free public BBDisplay and BBpager compatible service available on the web. It takes the well known BB model of delivering data and packages a large scale MySql Database schema around it and a world class web interface to

Alert On Failure

  

 The Engineers at Squidworks are building another free web services site. AlertOnFailure.com is the first free public BBDisplay and BBpager compatible service available on the web. It takes the well known BB model of delivering data and packages a large scale MySql Database schema around it and a world class web interface to view and manager the data collected. The clients are freely available across the Internet, some off the better clients are BBwin, XYMon and BB4.org. If you ever used BB, Hobbit or XYmon then this will be a great experence for you.

www.AlertOnFailure.com

Hobbit / XYMON / Big Brother

ELGG Plugin : My Online Friends Messenger

Here is a plugin for ELGG community web framework created to popout from side of browser and show your active friends by name and picture. Each online friend listed is hyperlinked back the the email composer with that friends ID pre posted. The plugin show users as active (5 minutes) and inactive (10 minutes) variations .

myfriends-1.0.tar

Here is a plugin for ELGG community web framework created to popout from side of browser and show your active friends by name and picture. Each online friend listed is hyperlinked back the the email composer with that friends ID pre posted. The plugin show users as active (5 minutes) and inactive (10 minutes) variations .

myfriends-1.0.tar

Howto: MySQL Full Text Search in PHP

This tutorial is intended for Text Searching using MySQL (http://www.MySQL.com/) and PHP (http://www.php.net) and will focus on the Full-text capabilities presented by MySQL.

Synopsis

We run a website that hosts web blogs, we have a database that contains blog posts. We might create a table in our database using a statement like this:

CREATE TABLE blogs (body TEXT, title VARCHAR(250), id INT NOT NULL auto_increment, PRIMARY KEY(id);
 

This tutorial is intended for Text Searching using MySQL (http://www.MySQL.com/) and PHP (http://www.php.net) and will focus on the Full-text capabilities presented by MySQL.

Synopsis

We run a website that hosts web blogs, we have a database that contains blog posts. We might create a table in our database using a statement like this:

CREATE TABLE blogs (body TEXT, title VARCHAR(250), id INT NOT NULL auto_increment, PRIMARY KEY(id);
 
 
 
 
 

 

How to modify your current database to accommodate Full-text searching.

Now we want to provide a simple search form and the ability to search keywords from the body field in the table “blog” of your database. First you will need to turn on Full Text Search for the table “blog” in your MySql database. Here is how to do that in MySql.

ALTER TABLE blog ADD FULLTEXT(body, title);

How to use a simple Full-text search to quickly gather relevant responses.

Lets create our PHP form and database query to support our search. I normally create a single php file called “search.php” then I “include(“search.php”)” where ever I want my search form and returning search data go but I can see where you may want to split this up and have the form and returning data in different areas so change as you see fit.

search.php
<?php
$keyword = $_POST[‘keyword’];
//we will assume your including this search in your index.php
//if not replace index wiht search.php or any page your going to do the sql query and display
//from.
?>
<h2>Search Our Archives</h2>
<form action=”index.php” enctype=”application/x-www-form-urlencoded” method=”post”>
<input name=”keyword” type=”text” />
<input type=”submit” value=”Search” />
</form>
<br>
<?php
if ($keyword != ”) {

        mysql_connect(“localhost”, “username”, “password”);

        mysql_select_db(“database_name”);

        $sql = ”
            SELECT body,
                MATCH(body) AGAINST(‘$keyword’) AS score
                FROM blog
            WHERE MATCH(body) AGAINST(‘$keyword’)
            ORDER BY score DESC
        “;
        $myresult = mysql_query($sql);
            while($row = mysql_fetch_array($myresult)) {
                echo “<table border=”0″><tbody><tr>”;
                echo “<td>Search – SCORE</td><td>Content</td></tr>”;
                echo “<tr><td><strong>” . $row[‘score’] . “</strong></td>”;
                echo “<td>” . $row[‘body’] . “</td></tr>”;
                echo “</tbody></table>”;
            }
    }
?>

This search.php makes a quick and easy Full Test Search form and display for the data. It checks $keywords to validate data before displaying the data in a table. It includes the MySQL score returned by the Full Text Search. I hope this helps someone out there get a search up and running fast.

Enjoy..