Browse Source

modify http https protocol

miles 10 years ago
parent
commit
da5576a22e
2 changed files with 4 additions and 3 deletions
  1. 1 1
      index.php
  2. 3 2
      u2s.php

+ 1 - 1
index.php

@@ -10,4 +10,4 @@
 	<input type="submit" />
 </form>
 </body>
-</html>
+</html>

+ 3 - 2
u2s.php

@@ -15,7 +15,8 @@ catch (PDOException $e) {
 $shortUrl = new ShortUrl($pdo);
 try {
     $code = $shortUrl->urlToShortCode($_POST["url"]);
-    printf('<p><strong>Short URL:</strong> <a href="%s/%2$s">%2$s</a></p>',$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'],
+    $http = isset($_SERVER['HTTPS'])?'https':'http';
+    printf('<p><strong>Short URL:</strong> <a href="%s/%2$s">%2$s</a></p>',$http.'://'.$_SERVER['HTTP_HOST'],
         SHORTURL_PREFIX . $code);
     exit;
 }
@@ -24,4 +25,4 @@ catch (Exception $e) {
 //     header("Location: /error");
     header("Location: index.php");
     exit;
-}
+}