Archive for February 2021


Php function to load table into a hash

February 24th, 2021 — 10:51am

Here’s a function I use to load mysql data into a hash for quick lookups in my code:

function select_sql_hash ($link,$sql,&$all_hash,$key) {
  $r = mysqli_query($link,$sql);
  if (!$r) {
   $message  = 'Invalid query: ' . mysqli_error() . "\n";
   $message .= 'Whole query: ' . $sql;
   print "$message\n";
        exit;
  }
  while ($results = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
        $all_hash[$results[$key]] = $results;
  }
  mysqli_free_result($r);
}
This can be called something like this:
$topics = array();
select_sql_hash($db,"select topicid,name,created_date from topic",$topics,"topicid");
The results is a hashed array where $topic[5][‘name’] is the “name” field for that topic, and $topic[5][‘created_date’] is the date created, etc. This is handy if the code is doing some mapping to print out topic names and you’d like to avoid joining the tables. Or it may save additional queries to the database when displaying data.

Comments Off on Php function to load table into a hash | php

Responsive website example

February 19th, 2021 — 8:38am

One way to tell a website that hasn’t been updated in a long time, or is defunct, is by whether or not it has a “responsive design”. Responsive designed sites are made to display nicely on any size screen – smartphones, tablets, laptops, etc. The essentially “redraw the layout” or respond to the available screen size. You can easily see this in action by loading up a site on your computer, then “shrinking” the screen (width wise). As it shrinks, the content should re-position itself (if it’s responsive) to fit on the current window size. There are many frameworks out there to facilitate responsive design. For the test site below, I used bootstrap:

https://quickthreads.com/

The site pulls in article summaries from several news sites daily for quick reading on any device. Below are screenshots of full screen and mobile views:

Full Size View


Mobile View


Comments Off on Responsive website example | mobile

Linux security issue

February 3rd, 2021 — 5:20pm

Recently, a new security issue with Linux came to light (https://nvd.nist.gov/vuln/detail/CVE-2021-3156), which could allow a user to gain root access of a server. This is using the “sudoedit” command, which is used to give users elevated privileges (but not root access) in some cases.

The first question a website / server owner should ask here is “Is my server vulnerable to this?” – if so, the next question is “who needs to fix it and how?”. In this particular case, only servers which allow normal “user” access need to be immediately concerned.

If you run / own a dedicated server with only trusted user accounts, the urgency to get patched is not as high. For sure, you should get it done, but it’s unlikely someone could exploit this bug.

If, however, you run a multi-user system with many untrusted users logging in, you probably need to act quickly. Once these bugs are revealed publicly, hackers will look to exploit them. Many hosting companies run jailed-shells, or otherwise restricted shells, so they may not be vulnerable. If you have a more vanilla Linux installation with multiple user accounts, you should get this patched.

Comments Off on Linux security issue | Security

Back to top