輸出 Content-Type: application/octet-stream 並設定 Content-Disposition: attachment,瀏覽器會下載一個 .url 檔案(Windows 網際網路捷徑),雙擊即可用預設瀏覽器開啟指定網址。
favicon.ico 放置網站根目錄,捷徑圖示才會顯示。shorturl.php:<?php
$shortcut = "[InternetShortcut]\n"
. "URL=https://www.example.com/\n"
. "IDList=\n"
. "[{000214A0-0000-0000-C000-000000000046}]\n"
. "Prop3=19,2\n";
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="MySite.url"');
echo $shortcut;
?>
<a href="/shorturl.php">📌 發送到桌面</a>
<?php
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
$url = "$scheme://$host$uri";
$shortcut = "[InternetShortcut]\n"
. "URL=$url\n"
. "IconFile=$scheme://$host/favicon.ico\n"
. "IDList=\n"
. "[{000214A0-0000-0000-C000-000000000046}]\n"
. "Prop3=19,2\n";
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . rawurlencode($host) . '.url"');
echo $shortcut;
?>
.url;macOS/Linux 需額外工具或改用 .webloc/.desktop 格式。manifest.json + Service Worker,支援「加入主畫面」且跨平台。