I have a gaming community website, that has some third-party tools associated with it (such as resource calculators, raid maps, etc) that I am designing.
I have a table in my database that stores these websites with the name of the site, the game it is for, the raw link (without the http/https), and its status (online, offline, maintenance).
How would I go about executing my current code to also check if the target URL is using http or https, and then redirect accordingly? I'm not having this set in the database, as sometimes certificates expire before they are renewed.
I'm not even sure where to begin. I know there is a get_header function in PHP, but not sure how to properly use that for my purposes, if that is even the correct function to use.
I have searched via google, and all results I get are for getting whether the target is http or https for site on the same box, which is not the case.
<?php
$result = $db->query('SELECT * FROM glist LIMIT 10');
if(is_object($result) && $result->num_rows > 0)
{
while($row = $result->fetch_array())
{
echo '<tr>';
echo '<td>'.$row['gname'].'</td>';
echo '<td>'.$row['game'].'</td>';
if($row['stat'] == 'Online')
{
echo '<td align="center"><img src="img/online.png" alt="Online" width="42" /></td>';
}
else if($row['stat'] == 'Maint')
{
echo '<td align="center"><img src="img/maint.png" alt="Maintenance" width="42" /></td>';
}
else
{
echo '<td align="center"><img src="img/offline.png" alt="Offline" width="42" /></td>';
}
echo '<td align="center"><a href="http://'.$row['link'].'" target="_blank"';
if($row['stat'] == 'Maint' || $row['stat'] == 'Offline')
{
echo 'style="pointer-events:none;"';
}
echo '><img src="img/link.png" alt="'.$row['gname'].'" /></a></td>';
echo '</tr>';
}
}
else
{
echo '<tr><td colspan="4"><p class="notice">No sites are currently available.</p></td></tr>';
}
?>
When the while loop executes for each entry, it should detect if the target url begins with http or https, and create a link appropriately.
Right now, I have to manually tell it to do one or the other (either in the while loop, or the database itself), which will become very tedious and time consuming as our community grows.