-
Notifications
You must be signed in to change notification settings - Fork 6
/
m.php
193 lines (164 loc) · 6.59 KB
/
m.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/****************************************************************************
**
** Copyright (C) 2012-2013 Andreas Jakl.
** All rights reserved.
** Contact: Andreas Jakl ([email protected])
**
** This file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
****************************************************************************/
/*
Nfc Geo Tags Redirection Script
v1.2.0
Summary
---------------------------------------------------------------------------
Generate platform-independent NFC Geo tags.
Use case
---------------------------------------------------------------------------
Direct the user to a certain point on a map. The NFC tag
contains location information (point of interest, POI).
The user touches the tag with his NFC phone. The phone opens the maps
application at the coordinates of the POI. This allows the user to
navigate to the point or to get more information.
Description
---------------------------------------------------------------------------
Some phones support the "geo:" URI scheme and connect that to a maps
app on the phone (e.g., the Nokia N9 or Android).
The default maps client on Windows 8 uses a bingmaps: URI scheme.
Other phones do not support URI scheme for opening maps, and should be
redirected to a web-based maps client instead (e.g., Symbian).
On Symbian, this method also triggers the Nokia Maps application.
To maximize compatibility of a tag to phones, you need to take the phone
OS into account and use the supported URL scheme. However, it is still
desirable to have only a single NFC tag, regardless of the phone OS.
The solution is to write a URL to this script to the tag. The script
detects the phone OS through its user agent, and will redirect it to
the appropriate URL. This allows having a single tag, which is compatible
to multiple mobile operating systems.
Depending on the phone, the redirection method also differs. Redirecting
a MeeGo or Android phone to a geo: URI should be done by sending a HTTP
header with the new location. Other phone browsers don't handle the
geo URIs for this kind of redirect, and need to be redirected using
JavaScript (or a manual link in case JavaScript is deactivated).
Usage
---------------------------------------------------------------------------
Upload m.php to PHP 4.x+ compatible web server.
Call with location information as parameter:
m.php?l=[latitude],[longitude]
Example:
http://www.nfcinteractor.com/m.php?l=60.17,24.829
Alternatively, you can configure a custom place name in
the [CUSTOM PLACE NAMES] section. Then, you can store the
coordinates in the script and don't have to pass them via parameters:
m.php?c=[custom place name]
Example:
http://www.nfcinteractor.com/m.php?c=nokia
Advanced Usage
---------------------------------------------------------------------------
If your Apache-based web server supports URL rewrites using the
mod_rewrite module, you can allow calling the script without adding
the ".php" to the URL, thus saving four bytes on the tag.
Example:
http://www.nfcinteractor.com/m?l=60.17,24.829
To enable this, add the following .htaccess file in the same directory where
you place the m.php script:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^m$ m.php
</IfModule>
*/
// Default location: Nokia House, Espoo, Finland
$location = "60.17,24.829";
// Check if any coordinates are set in the URL
if (isset($_GET['l']) || isset($_GET['c'])) {
$lparam = isset($_GET['l']) ? $_GET['l'] : $_GET['c'];
// Encode a + as %2B in the URL parameter if needed
if (preg_match('/^[\-+]?\d+\.?\d+[,]{1}[\-+]?\d+\.?\d+$/', $lparam) == 1) {
// Use provided coordinates
$location = $lparam;
} else {
$locationString = strtolower($lparam);
// [CUSTOM PLACE NAMES]
// Provide custom place names here.
// Allows calling the script by just using a textual place name
// instead of coordinates, which allows for greater flexibility.
// The script then replaces the place name with the coordinates.
switch ($locationString) {
case "nokia":
$location = "60.17,24.829";
break;
}
}
}
// Encoded platform names
// s = Symbian
// h = MeeGo Harmattan
// f = Series 40
// w8 = Windows 8
// wp8 = Windows Phone 8.x - will be added once SDK is available
// wp7 = Windows Phone 7.x
// a = Android
// i = iPhone
// b = RIM BlackBerry
// Stores encoded platform name
$ua_enc = '';
// Check user agent and assign encoded platform name
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$locationUri = "http://m.nokia.me/?c=".$location."&z=15";
$redirectionMethod = 2; // 1 = Header redirection, 2 = JavaScript
if (preg_match('/symbian/i',$user_agent)) {
$ua_enc = 's';
$locationUri = "http://m.ovi.me/?c=".$location."&z=15";
} elseif (preg_match('/meego/i',$user_agent)) {
$ua_enc = 'h';
$locationUri = "geo:".$location;
$redirectionMethod = 1;
} elseif (preg_match('/Windows NT 6.2/i',$user_agent)) {
$ua_enc = 'w8';
$locationTilde = str_replace(',', '~', $location);
$locationUri = "bingmaps://?cp=".$locationTilde;
} elseif (preg_match('/windows phone/i',$user_agent)) {
$ua_enc = 'wp7';
$locationSpace = str_replace(',', ' ', $location);
$locationUri = "maps:".$locationSpace;
} elseif (preg_match('/nokia/i',$user_agent)) {
$ua_enc = 'f';
} elseif (preg_match('/android/i',$user_agent)) {
$ua_enc = 'a';
$locationUri = "geo:".$location;
$redirectionMethod = 1;
} elseif (preg_match('/iphone/i',$user_agent) || preg_match('/ipad/i',$user_agent)) {
$ua_enc = 'i';
} elseif (preg_match('/blackberry/i',$user_agent)) {
$ua_enc = 'b';
}
if ($redirectionMethod == 1) {
// The phone supports direct redirection by sending a new header.
header("Location: ".$locationUri);
exit;
}
// For other phones, redirect the phone via a JavaScript redirect
// (e.g., using the header redirection on Symbian would not trigger opening the
// Nokia Maps client).
?>
<html>
<head>
<script type="text/javascript">
<!--
window.location = "<?php echo $locationUri; ?>";
//-->
</script>
</head>
<body>
<!--<noscript>-->
<font face="Tahoma,Arial"><a href="<?php echo $locationUri; ?>&z=15">Open Maps</a></font>
<!--</noscript>-->
</body>
</html>