Home  >  Article  >  Backend Development  >  php generates web page desktop shortcut

php generates web page desktop shortcut

WBOY
WBOYOriginal
2016-07-29 09:08:501628browse

This article will introduce the code to use php to generate web desktop shortcuts, add icons and solve the garbled problem that occurs when saving in different browsers.

When we visit a website, if the content of the website is very attractive, we usually use the browser’s favorites function to bookmark this website.
For web pages that are favorited in the browser, you need to open the browser and then select and access them from the favorites.

If you can enter the website directly from the desktop, it will facilitate user access.
We can use PHP to create a shortcut entry file for the web page and save it to the user's desktop for quick access.
The generated code is as follows:

<code><span><span><?php </span><span>$filename</span> = <span>'破晓领域.url'</span>;
<span>$url</span> = <span>'http://fdipzone.com/'</span>;
<span>$icon</span> = <span>'http://fdipzone.com/favicon.ico'</span>;

createShortCut(<span>$filename</span>, <span>$url</span>, <span>$icon</span>);

<span>/**
 * 创建保存为桌面代码
 *<span> @param</span> String $filename 保存的文件名
 *<span> @param</span> String $url      访问的连接
 *<span> @param</span> String $icon     图标路径
 */</span><span><span>function</span><span>createShortCut</span><span>(<span>$filename</span>, <span>$url</span>, <span>$icon</span>=<span>''</span>)</span>{</span><span>// 创建基本代码</span><span>$shortCut</span> = <span>"[InternetShortcut]\r\nIDList=[{000214A0-0000-0000-C000-000000000046}]\r\nProp3=19,2\r\n"</span>;
    <span>$shortCut</span> .= <span>"URL="</span>.<span>$url</span>.<span>"\r\n"</span>;
    <span>if</span>(<span>$icon</span>){
        <span>$shortCut</span> .= <span>"Ic>$icon</span>.<span>""</span>;
    }

    header(<span>"content-type:application/octet-stream"</span>);

    <span>// 获取用户浏览器</span><span>$user_agent</span> = <span>$_SERVER</span>[<span>'HTTP_USER_AGENT'</span>];
    <span>$encode_filename</span> = rawurlencode(<span>$filename</span>);

    <span>// 不同浏览器使用不同编码输出</span><span>if</span>(preg_match(<span>"/MSIE/"</span>, <span>$user_agent</span>)){
        header(<span>'content-disposition:attachment; filename="'</span>.<span>$encode_filename</span>.<span>'"'</span>);
    }<span>else</span><span>if</span>(preg_match(<span>"/Firefox/"</span>, <span>$user_agent</span>)){
        header(<span>"content-disposition:attachment; filename*=\"utf8''"</span>.<span>$filename</span>.<span>'"'</span>);
    }<span>else</span>{
        header(<span>'content-disposition:attachment; filename="'</span>.<span>$filename</span>.<span>'"'</span>);
    }

    <span>echo</span><span>$shortCut</span>;

}
<span>?></span></span></span></code>


Download and save to desktop
php generates web page desktop shortcut
Save to desktop
php generates web page desktop shortcut

After saving as *.url on desktop, click to automatically open the browser and access the website content.

The content of the Dawn Realm.url file is as follows:

<code><span>[InternetShortcut]</span><span>IDList=<span>[{<span>000214</span>A0-<span>0000</span>-<span>0000</span>-C000-<span>000000000046</span>}]</span></span><span>Prop3=<span><span>19</span>,<span>2</span></span></span><span>URL=<span>http://fdipzone.com/</span></span><span>Ic>http://fdipzone.com/favicon.ico</span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces how to use PHP to generate web page desktop shortcuts, including related content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn