這篇文章主要介紹了php建立案頭捷徑實現方法
第一種情況:php產生網頁案頭捷徑
將介紹使用php產生網頁案頭捷徑的代碼,並添加表徵圖及解決不同瀏覽器儲存出現的亂碼問題。
我們訪問網站時,如果網站的內容很有吸引,一般我們都會使用瀏覽器的收藏夾功能,收藏此網站。
在瀏覽器收藏的網頁,需要開啟瀏覽器,再從收藏夾選定訪問。
如果可以在案頭直接進入到網站,這樣可以為使用者訪問提供便利。
我們可以使用php建立網頁的快捷入口檔案,儲存到使用者案頭,方便使用者快速存取。
產生代碼如下:
<?php$filename = '破曉領域.url';$url = 'http://fdipzone.com/';$icon = 'http://fdipzone.com/favicon.ico';createShortCut($filename, $url, $icon);/** * 建立儲存為案頭代碼 * @param String $filename 儲存的檔案名稱 * @param String $url 訪問的串連 * @param String $icon 表徵圖路徑 */function createShortCut($filename, $url, $icon=''){ // 建立基本代碼 $shortCut = "[InternetShortcut]\r\nIDList=[{000214A0-0000-0000-C000-000000000046}]\r\nProp3=19,2\r\n"; $shortCut .= "URL=".$url."\r\n"; if($icon){ $shortCut .= "IconFile=".$icon.""; } header("content-type:application/octet-stream"); // 擷取使用者瀏覽器 $user_agent = $_SERVER['HTTP_USER_AGENT']; $encode_filename = rawurlencode($filename); // 不同瀏覽器使用不同編碼輸出 if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); } echo $shortCut;}?>
下載儲存到案頭
儲存到案頭
在案頭儲存為*.url後,點擊就能自動開啟瀏覽器並訪問網站內容了。
第二種情況:PHP實現網站儲存快捷案頭方式
<?php/*儲存shortcut.php訪問即可儲存案頭*/$title="指令碼之家";$Shortcut = "[InternetShortcut]URL=http://www.jb51.netIDList= [{000214A0-0000-0000-C000-000000000046}] Prop3=19,2";Header("Content-type: application/octet-stream");header("Content-Disposition: attachment; filename=".$title.".url;");echo $Shortcut;?>
第三種情況:PHP產生網站案頭捷徑
PHP產生案頭捷徑就是這麼的簡單,大家產生的時候改下你要產生的網站即可。
dianji.html代碼:
<a href="a.php?url=www.jb51.net&name=指令碼之家">產生左面捷徑</a>
shengcheng.php代碼:
<?php//網站生存左面捷徑---功能 $url = $_GET['url']; $filename = urldecode($_GET['name']); $filename = iconv('GBk','utf-8',$filename);//字元集轉換(沒有需要轉的就不轉) if (!$url || !$filename) exit();$Shortcut = "[InternetShortcut] URL={$url}IDList= [{000214A0-0000-0000-C000-000000000046}] Prop3=19,2"; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename={$filename}.url;");echo $Shortcut; ?>