0

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.

Strages
  • 13
  • 5
  • generally speaking you could assume that if the target site support http they would automatically redirect it. However, here is a SO answer that fit your needs: https://stackoverflow.com/a/39176483/10864482 –  Jul 05 '19 at 21:30
  • Possible duplicate of [Check if a website is using SSL using CURL](https://stackoverflow.com/questions/36950874/check-if-a-website-is-using-ssl-using-curl) –  Jul 05 '19 at 21:32
  • That actually helps alot, and answered my question. I have never used CURL before, so never thought to look it up as an option. – Strages Jul 05 '19 at 21:37
  • If I was doing this I would have a table of sites with a field for HTTP vs HTTPS, and perhaps have a cron job to update the field once a day or week. If you serve up a lot of links that's more polite (and much faster) than pinging the other server every time you serve up a link to it. – Dave S Jul 05 '19 at 21:53

0 Answers0