Advertisement
leors

SSL SNI detect

Oct 25th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <?php
  3. $hasSSL = (empty($_GET['nossl']) && (!empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'on' || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'));
  4.  
  5. $forceNoSSL = isset($_GET['nossl']) && $_GET['nossl'] == 1;
  6. $redirectNoSSL = '';
  7. if(!$forceNoSSL)
  8. {
  9.     $redirectNoSSL = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
  10.     $redirectNoSSL.= (empty($_SERVER['QUERY_STRING']) ? '?' : '&') . 'nossl=1';
  11. }
  12. ?>
  13. <html>
  14.     <head>
  15.         <title>SNI-Detection Demo</title>
  16.         <? if(!$hasSSL): ?>
  17.         <? if(!$forceNoSSL && $redirectNoSSL):?><meta http-equiv="refresh" content="1; URL="http://<?=$redirectNoSSL;?>"/><? endif; ?>
  18.         <script type="text/javascript" src="sni-detect.js" data-cfasync="false"></script>
  19.         <? endif; ?>
  20.         <style type="text/css">
  21.             body { font-family: Arial; font-size: 1em; }
  22.         </style>
  23.     </head>
  24.     <body>
  25.         <? if($forceNoSSL): ?>
  26.         <p>
  27.             <b>Result:</b><br />
  28.             <b style="color:red;">Sorry!</b><br /><br />
  29.             Your Browser defenitely NOT supports SNI-SSL and you have been redirected before by the SNI-Detection-Script.
  30.         </p>
  31.         <? elseif($hasSSL && !$forceNoSSL): ?>
  32.         <p>
  33.             <b>Result:</b><br />
  34.             <b style="color:green;">Gratulations!</b><br /><br />
  35.             Your Browser seems to support SNI-SSL as you are already using SSL
  36.             with SNI-vHost and may have been redirected before by the SNI-Detection-Script.
  37.         </p>
  38.         <? else: ?>
  39.         <p id="sni-detection-result">
  40.             Trying to detemine if Browser supports SNI-SSL.
  41.             <noscript>
  42.                 <p>Javascript is disabled. So we are using Non-SSL mode and meta-redirect.</p>
  43.             </noscript>
  44.         </p>
  45.         <? endif; ?>
  46.     </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement