Have you ever wondered that having to remember and type the URL of your webpage over and again might be frustrating for some users of your website? That was why the internet shortcut was created to help out.
The Internet Shortcut / URL file (*.URL) is a Windows file which can however be used on other OS or better stated by browsers on other OS other than Windows. This is used extensively in IE to store bookmarks and favorites but can also be used to create a double clickable file (shortcut) similar to a file shortcut rather pointing to an internet resource and recognized by all major browser.
The file format is similar to an INI file and has the .URL extension (note .url doesn’t seem to work for some people but .URL works in all cases)
[InternetShortcut] URL=http://www.example.com/index.php Workingdirctory=c:\Windows\ ShowCommand=7 IconIndex=1 IconFile=c:\Windows\system\url.dll . . .
There are still some other field but the most important are the URL and ShowCommand fields:
URL
ShowCommand
Being able to generate this on the fly on the server side and letting the user download it their computer will be of great benefit in that
The code below shows our to set the URL field (which is the only necessary and most important field to set) from the server side, preparing the file and shipping it to the user for download.
<?php $protocol = "http://"; if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { $protocol = "https://"; } $shortText = "[InternetShortcut]\nURL={$protocol}" . $_SERVER['SERVER_NAME']; // We'll be outputting an internet shortcut file header('Content-type: application/internet-shortcut'); // It will be called myShortCut.URL header('Content-Disposition: attachment; filename="myShortCut.URL"'); //output URL file echo $shortText; ?>
The MIME (content-type) could be any of wwwserver/redirection, application/internet-shortcut, application/x-url, message/external-body, text/url, text/x-url but application/internet-shortcut works fine.