Android permission 权限类中英文说明
public final class Manifest { |
002 |
public static final class permission { |
003 |
/** Allows read/write access to the "properties" table in the checkin |
004 |
database, to change values that get uploaded. |
005 |
*/ |
006 |
public static final String ACCESS_CHECKIN_PROPERTIES="android.permission.ACCESS_CHECKIN_PROPERTIES"; |
007 |
/** Allows an application to access coarse (e.g., Cell-ID, WiFi) location |
008 |
*/ |
009 |
public static final String ACCESS_COARSE_LOCATION="android.permission.ACCESS_COARSE_LOCATION"; |
010 |
/** Allows an application to access fine (e.g., GPS) location |
011 |
*/ |
012 |
public static final String ACCESS_FINE_LOCATION="android.permission.ACCESS_FINE_LOCATION"; |
013 |
/** Allows an application to access extra location provider commands |
014 |
*/ |
015 |
public static final String ACCESS_LOCATION_EXTRA_COMMANDS="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"; |
016 |
/** Allows an application to create mock location providers for testing |
017 |
*/ |
018 |
public static final String ACCESS_MOCK_LOCATION="android.permission.ACCESS_MOCK_LOCATION"; |
019 |
/** Allows applications to access information about networks |
020 |
*/ |
021 |
public static final String ACCESS_NETWORK_STATE="android.permission.ACCESS_NETWORK_STATE"; |
022 |
/** Allows an application to use SurfaceFlinger¹s low level features |
023 |
*/ |
024 |
public static final String ACCESS_SURFACE_FLINGER="android.permission.ACCESS_SURFACE_FLINGER"; |
025 |
/** Allows applications to access information about Wi-Fi networks |
026 |
*/ |
027 |
public static final String ACCESS_WIFI_STATE="android.permission.ACCESS_WIFI_STATE"; |
028 |
/** Allows an application to publish system-level services. Such services |
029 |
can only be published from processes that never go away, so this is |
030 |
not something that any normal application can do. |
031 |
*/ |
032 |
public static final String ADD_SYSTEM_SERVICE="android.permission.ADD_SYSTEM_SERVICE"; |
033 |
/** Allows an application to update the collected battery statistics |
034 |
*/ |
035 |
public static final String BATTERY_STATS="android.permission.BATTERY_STATS"; |
036 |
/** Allows applications to connect to paired bluetooth devices |
037 |
*/ |
038 |
public static final String BLUETOOTH="android.permission.BLUETOOTH"; |
039 |
/** Allows applications to discover and pair bluetooth devices |
040 |
*/ |
041 |
public static final String BLUETOOTH_ADMIN="android.permission.BLUETOOTH_ADMIN"; |
042 |
/** Required to be able to disable the device (very dangerous!). |
043 |
*/ |
044 |
public static final String BRICK="android.permission.BRICK"; |
045 |
/** Allows an application to broadcast a notification that an application |
046 |
package has been removed. |
047 |
*/ |
048 |
public static final String BROADCAST_PACKAGE_REMOVED="android.permission.BROADCAST_PACKAGE_REMOVED"; |
049 |
/** Allows an application to broadcast sticky intents. These are |
050 |
broadcasts whose data is held by the system after being finished, |
051 |
so that clients can quickly retrieve that data without having |
052 |
to wait for the next broadcast. |
053 |
*/ |
054 |
public static final String BROADCAST_STICKY="android.permission.BROADCAST_STICKY"; |
055 |
/** Allows an application to initiate a phone call without going through |
056 |
the Dialer user interface for the user to confirm the call |
057 |
being placed. |
058 |
*/ |
059 |
public static final String CALL_PHONE="android.permission.CALL_PHONE"; |
060 |
/** Allows an application to call any phone number, including emergency |
061 |
numbers, without going through the Dialer user interface for the user |
062 |
to confirm the call being placed. |
063 |
*/ |
064 |
public static final String CALL_PRIVILEGED="android.permission.CALL_PRIVILEGED"; |
065 |
/** Required to be able to access the camera device. |
066 |
*/ |
067 |
public static final String CAMERA="android.permission.CAMERA"; |
068 |
/** Allows an application to change whether an application component (other than its own) is |
069 |
enabled or not. |
070 |
*/ |
071 |
public static final String CHANGE_COMPONENT_ENABLED_STATE="android.permission.CHANGE_COMPONENT_ENABLED_STATE"; |
072 |
/** Allows an application to modify the current configuration, such |
073 |
as locale. |
074 |
*/ |
075 |
public static final String CHANGE_CONFIGURATION="android.permission.CHANGE_CONFIGURATION"; |
076 |
/** Allows applications to change network connectivity state |
077 |
*/ |
078 |
public static final String CHANGE_NETWORK_STATE="android.permission.CHANGE_NETWORK_STATE"; |
079 |
/** Allows applications to change Wi-Fi connectivity state |
080 |
*/ |
081 |
public static final String CHANGE_WIFI_STATE="android.permission.CHANGE_WIFI_STATE"; |
082 |
/** Allows an application to clear the caches of all installed |
083 |
applications on the device. |
084 |
*/ |
085 |
public static final String CLEAR_APP_CACHE="android.permission.CLEAR_APP_CACHE"; |
086 |
/** Allows an application to clear user data |
087 |
*/ |
088 |
public static final String CLEAR_APP_USER_DATA="android.permission.CLEAR_APP_USER_DATA"; |
089 |
/** Allows enabling/disabling location update notifications from |
090 |
the radio. Not for use by normal applications. |
091 |
*/ |
092 |
public static final String CONTROL_LOCATION_UPDATES="android.permission.CONTROL_LOCATION_UPDATES"; |
093 |
/** Allows an application to delete cache files. |
094 |
*/ |
095 |
public static final String DELETE_CACHE_FILES="android.permission.DELETE_CACHE_FILES"; |
096 |
/** Allows an application to delete packages. |
097 |
*/ |
098 |
public static final String DELETE_PACKAGES="android.permission.DELETE_PACKAGES"; |
099 |
/** Allows low-level access to power management |
100 |
*/ |
101 |
public static final String DEVICE_POWER="android.permission.DEVICE_POWER"; |
102 |
/** Allows applications to RW to diagnostic resources. |
103 |
*/ |
104 |
public static final String DIAGNOSTIC="android.permission.DIAGNOSTIC"; |
105 |
/** Allows applications to disable the keyguard |
106 |
*/ |
107 |
public static final String DISABLE_KEYGUARD="android.permission.DISABLE_KEYGUARD"; |
108 |
/** Allows an application to retrieve state dump information from system |
109 |
services. |
110 |
*/ |
111 |
public static final String DUMP="android.permission.DUMP"; |
112 |
/** Allows an application to expand or collapse the status bar. |
113 |
*/ |
114 |
public static final String EXPAND_STATUS_BAR="android.permission.EXPAND_STATUS_BAR"; |
115 |
/** Run as a manufacturer test application, running as the root user. |
116 |
Only available when the device is running in manufacturer test mode. |
117 |
*/ |
118 |
public static final String FACTORY_TEST="android.permission.FACTORY_TEST"; |
119 |
/** Allows access to the flashlight |
120 |
*/ |
121 |
public static final String FLASHLIGHT="android.permission.FLASHLIGHT"; |
122 |
/** Allows an application to force a BACK operation on whatever is the |
123 |
top activity. |
124 |
*/ |
125 |
public static final String FORCE_BACK="android.permission.FORCE_BACK"; |
126 |
public static final String FOTA_UPDATE="android.permission.FOTA_UPDATE"; |
127 |
/** Allows access to the list of accounts in the Accounts Service |
128 |
*/ |
129 |
public static final String GET_ACCOUNTS="android.permission.GET_ACCOUNTS"; |
130 |
/** Allows an application to find out the space used by any package. |
131 |
*/ |
132 |
public static final String GET_PACKAGE_SIZE="android.permission.GET_PACKAGE_SIZE"; |
133 |
/** Allows an application to get information about the currently |
134 |
or recently running tasks: a thumbnail representation of the tasks, |
135 |
what activities are running in it, etc. |
136 |
*/ |
137 |
public static final String GET_TASKS="android.permission.GET_TASKS"; |
138 |
/** Allows access to hardware peripherals. Intended only for hardware testing |
139 |
*/ |
140 |
public static final String HARDWARE_TEST="android.permission.HARDWARE_TEST"; |
141 |
/** Allows an application to inject user events (keys, touch, trackball) |
142 |
into the event stream and deliver them to ANY window. Without this |
143 |
permission, you can only deliver events to windows in your own process. |
144 |
Very few applications should need to use this permission. |
145 |
*/ |
146 |
public static final String INJECT_EVENTS="android.permission.INJECT_EVENTS"; |
147 |
/** Allows an application to install packages. |
148 |
*/ |
149 |
public static final String INSTALL_PACKAGES="android.permission.INSTALL_PACKAGES"; |
150 |
/** Allows an application to open windows that are for use by parts |
151 |
of the system user interface. Not for use by third party apps. |
152 |
*/ |
153 |
public static final String INTERNAL_SYSTEM_WINDOW="android.permission.INTERNAL_SYSTEM_WINDOW"; |
154 |
/** Allows applications to open network sockets. |
155 |
*/ |
156 |
public static final String INTERNET="android.permission.INTERNET"; |
157 |
/** Allows an application to manage (create, destroy, |
158 |
Z-order) application tokens in the window manager. This is only |
159 |
for use by the system. |
160 |
*/ |
161 |
public static final String MANAGE_APP_TOKENS="android.permission.MANAGE_APP_TOKENS"; |
162 |
public static final String MASTER_CLEAR="android.permission.MASTER_CLEAR"; |
163 |
/** Allows an application to modify global audio settings |
164 |
*/ |
165 |
public static final String MODIFY_AUDIO_SETTINGS="android.permission.MODIFY_AUDIO_SETTINGS"; |
166 |
/** Allows modification of the telephony state - power on, mmi, etc. |
167 |
Does not include placing calls. |
168 |
*/ |
169 |
public static final String MODIFY_PHONE_STATE="android.permission.MODIFY_PHONE_STATE"; |
170 |
/** Allows mounting and unmounting file systems for removable storage. |
171 |
*/ |
172 |
public static final String MOUNT_UNMOUNT_FILESYSTEMS="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"; |
173 |
/** Allow an application to make its activities persistent. |
174 |
*/ |
175 |
public static final String PERSISTENT_ACTIVITY="android.permission.PERSISTENT_ACTIVITY"; |
176 |
/** Allows an application to monitor, modify, or abort outgoing |
177 |
calls. |
178 |
*/ |
179 |
public static final String PROCESS_OUTGOING_CALLS="android.permission.PROCESS_OUTGOING_CALLS"; |
180 |
/** Allows an application to read the user¹s calendar data. |
181 |
*/ |
182 |
public static final String READ_CALENDAR="android.permission.READ_CALENDAR"; |
183 |
/** Allows an application to read the user¹s contacts data. |
184 |
*/ |
185 |
public static final String READ_CONTACTS="android.permission.READ_CONTACTS"; |
186 |
/** Allows an application to take screen shots and more generally |
187 |
get access to the frame buffer data |
188 |
*/ |
189 |
public static final String READ_FRAME_BUFFER="android.permission.READ_FRAME_BUFFER"; |
190 |
/** Allows an application to retrieve the current state of keys and |
191 |
switches. This is only for use by the system. |
192 |
*/ |
193 |
public static final String READ_INPUT_STATE="android.permission.READ_INPUT_STATE"; |
194 |
/** Allows an application to read the low-level system log files. |
195 |
These can contain slightly private information about what is |
196 |
happening on the device, but should never contain the user¹s |
197 |
private information. |
198 |
*/ |
199 |
public static final String READ_LOGS="android.permission.READ_LOGS"; |
200 |
/** Allows an application to read the owner¹s data. |
201 |
*/ |
202 |
public static final String READ_OWNER_DATA="android.permission.READ_OWNER_DATA"; |
203 |
/** Allows read only access to phone state. |
204 |
*/ |
205 |
public static final String READ_PHONE_STATE="android.permission.READ_PHONE_STATE"; |
206 |
/** Allows an application to read SMS messages. |
207 |
*/ |
208 |
public static final String READ_SMS="android.permission.READ_SMS"; |
209 |
/** Allows applications to read the sync settings |
210 |
*/ |
211 |
public static final String READ_SYNC_SETTINGS="android.permission.READ_SYNC_SETTINGS"; |
212 |
/** Allows applications to read the sync stats |
213 |
*/ |
214 |
public static final String READ_SYNC_STATS="android.permission.READ_SYNC_STATS"; |
215 |
/** Required to be able to reboot the device. |
216 |
*/ |
217 |
public static final String REBOOT="android.permission.REBOOT"; |
218 |
/** Allows an application to receive the |
219 |
{@link android.content.Intent#ACTION_BOOT_COMPLETED} that is |
220 |
broadcast after the system finishes booting. If you don¹t |
221 |
request this permission, you will not receive the broadcast at |
222 |
that time. Though holding this permission does not have any |
223 |
security implications, it can have a negative impact on the |
224 |
user experience by increasing the amount of time it takes the |
225 |
system to start and allowing applications to have themselves |
226 |
running without the user being aware of them. As such, you must |
227 |
explicitly declare your use of this facility to make that visible |
228 |
to the user. |
229 |
*/ |
230 |
public static final String RECEIVE_BOOT_COMPLETED="android.permission.RECEIVE_BOOT_COMPLETED"; |
231 |
/** Allows an application to monitor incoming MMS messages, to record |
232 |
or perform processing on them. |
233 |
*/ |
234 |
public static final String RECEIVE_MMS="android.permission.RECEIVE_MMS"; |
235 |
/** Allows an application to monitor incoming SMS messages, to record |
236 |
or perform processing on them. |
237 |
*/ |
238 |
public static final String RECEIVE_SMS="android.permission.RECEIVE_SMS"; |
239 |
/** Allows an application to monitor incoming WAP push messages. |
240 |
*/ |
241 |
public static final String RECEIVE_WAP_PUSH="android.permission.RECEIVE_WAP_PUSH"; |
242 |
/** Allows an application to record audio |
243 |
*/ |
244 |
public static final String RECORD_AUDIO="android.permission.RECORD_AUDIO"; |
245 |
/** Allows an application to change the Z-order of tasks |
246 |
*/ |
247 |
public static final String REORDER_TASKS="android.permission.REORDER_TASKS"; |
248 |
/** Allows an application to restart other applications. |
249 |
*/ |
250 |
public static final String RESTART_PACKAGES="android.permission.RESTART_PACKAGES"; |
251 |
/** Allows an application to send SMS messages. |
252 |
*/ |
253 |
public static final String SEND_SMS="android.permission.SEND_SMS"; |
254 |
/** Allows an application to watch and control how activities are |
255 |
started globally in the system. Only for is in debugging |
256 |
(usually the monkey command). |
257 |
*/ |
258 |
public static final String SET_ACTIVITY_WATCHER="android.permission.SET_ACTIVITY_WATCHER"; |
259 |
/** Allows an application to control whether activities are immediately |
260 |
finished when put in the background. |
261 |
*/ |
262 |
public static final String SET_ALWAYS_FINISH="android.permission.SET_ALWAYS_FINISH"; |
263 |
/** Modify the global animation scaling factor. |
264 |
*/ |
265 |
public static final String SET_ANIMATION_SCALE="android.permission.SET_ANIMATION_SCALE"; |
266 |
/** Configure an application for debugging. |
267 |
*/ |
268 |
public static final String SET_DEBUG_APP="android.permission.SET_DEBUG_APP"; |
269 |
/** Allows low-level access to setting the orientation (actually |
270 |
rotation) of the screen. Not for use by normal applications. |
271 |
*/ |
272 |
public static final String SET_ORIENTATION="android.permission.SET_ORIENTATION"; |
273 |
/** Allows an application to modify the list of preferred applications |
274 |
with the {@link android.content.pm.PackageManager#addPackageToPreferred |
275 |
PackageManager.addPackageToPreferred()} and |
276 |
{@link android.content.pm.PackageManager#removePackageFromPreferred |
277 |
PackageManager.removePackageFromPreferred()} methods. |
278 |
*/ |
279 |
public static final String SET_PREFERRED_APPLICATIONS="android.permission.SET_PREFERRED_APPLICATIONS"; |
280 |
/** Allows an application to force any currently running process to be |
281 |
in the foreground. |
282 |
*/ |
283 |
public static final String SET_PROCESS_FOREGROUND="android.permission.SET_PROCESS_FOREGROUND"; |
284 |
/** Allows an application to set the maximum number of (not needed) |
285 |
application processes that can be running. |
286 |
*/ |
287 |
public static final String SET_PROCESS_LIMIT="android.permission.SET_PROCESS_LIMIT"; |
288 |
/** Allows applications to set the system time zone |
289 |
*/ |
290 |
public static final String SET_TIME_ZONE="android.permission.SET_TIME_ZONE"; |
291 |
/** Allows applications to set the wallpaper |
292 |
*/ |
293 |
public static final String SET_WALLPAPER="android.permission.SET_WALLPAPER"; |
294 |
/** Allows applications to set the wallpaper hints |
295 |
*/ |
296 |
public static final String SET_WALLPAPER_HINTS="android.permission.SET_WALLPAPER_HINTS"; |
297 |
/** Allow an application to request that a signal be sent to all persistent processes |
298 |
*/ |
299 |
public static final String SIGNAL_PERSISTENT_PROCESSES="android.permission.SIGNAL_PERSISTENT_PROCESSES"; |
300 |
/** Allows an application to open, close, or disable the status bar |
301 |
and its icons. |
302 |
*/ |
303 |
public static final String STATUS_BAR="android.permission.STATUS_BAR"; |
304 |
/** Allows an application to allow access the subscribed feeds |
305 |
ContentProvider. |
306 |
*/ |
307 |
public static final String SUBSCRIBED_FEEDS_READ="android.permission.SUBSCRIBED_FEEDS_READ"; |
308 |
public static final String SUBSCRIBED_FEEDS_WRITE="android.permission.SUBSCRIBED_FEEDS_WRITE"; |
309 |
/** Allows an application to open windows using the type |
310 |
{@link android.view.WindowManager.LayoutParams#TYPE_SYSTEM_ALERT}, |
311 |
shown on top of all other applications. Very few applications |
312 |
should use this permission; these windows are intended for |
313 |
system-level interaction with the user. |
314 |
*/ |
315 |
public static final String SYSTEM_ALERT_WINDOW="android.permission.SYSTEM_ALERT_WINDOW"; |
316 |
/** Allows access to the vibrator |
317 |
*/ |
318 |
public static final String VIBRATE="android.permission.VIBRATE"; |
319 |
/** Allows using PowerManager WakeLocks to keep processor from sleeping or screen |
320 |
from dimming |
321 |
*/ |
322 |
public static final String WAKE_LOCK="android.permission.WAKE_LOCK"; |
323 |
/** Allows applications to write the apn settings |
324 |
*/ |
325 |
public static final String WRITE_APN_SETTINGS="android.permission.WRITE_APN_SETTINGS"; |
326 |
/** Allows an application to write (but not read) the user¹s |
327 |
calendar data. |
328 |
*/ |
329 |
public static final String WRITE_CALENDAR="android.permission.WRITE_CALENDAR"; |
330 |
/** Allows an application to write (but not read) the user¹s |
331 |
contacts data. |
332 |
*/ |
333 |
public static final String WRITE_CONTACTS="android.permission.WRITE_CONTACTS"; |
334 |
/** Allows an application to modify the Google service map. |
335 |
*/ |
336 |
public static final String WRITE_GSERVICES="android.permission.WRITE_GSERVICES"; |
337 |
/** Allows an application to write (but not read) the owner¹s data. |
338 |
*/ |
339 |
public static final String WRITE_OWNER_DATA="android.permission.WRITE_OWNER_DATA"; |
340 |
/** Allows an application to read or write the system settings. |
341 |
*/ |
342 |
public static final String WRITE_SETTINGS="android.permission.WRITE_SETTINGS"; |
343 |
/** Allows an application to write SMS messages. |
344 |
*/ |
345 |
public static final String WRITE_SMS="android.permission.WRITE_SMS"; |
346 |
/** Allows applications to write the sync settings |
347 |
*/ |
348 |
public static final String WRITE_SYNC_SETTINGS="android.permission.WRITE_SYNC_SETTINGS"; |
349 |
} |
350 |
public static final class permission_group { |
351 |
/** Permissions for direct access to Google accounts. |
352 |
Note that while right now this is only used for Google accounts, |
353 |
we expect in the future to have a more general account management |
354 |
facility so this is specified as a general platform permission |
355 |
group for accessing accounts. |
356 |
*/ |
357 |
public static final String ACCOUNTS="android.permission-group.ACCOUNTS"; |
358 |
/** Used for permissions that can be used to make the user spend money |
359 |
without their direct involvement. For example, this is the group |
360 |
for permissions that allow you to directly place phone calls, |
361 |
directly send SMS messages, etc. |
362 |
*/ |
363 |
public static final String COST_MONEY="android.permission-group.COST_MONEY"; |
364 |
/** Group of permissions that are related to development features. These |
365 |
are not permissions that should appear in normal applications; they |
366 |
protect APIs that are intended only to be used for development |
367 |
purposes. |
368 |
*/ |
369 |
public static final String DEVELOPMENT_TOOLS="android.permission-group.DEVELOPMENT_TOOLS"; |
370 |
/** Used for permissions that provide direct access to the hardware on |
371 |
the device. This includes audio, the camera, vibrator, etc. |
372 |
*/ |
373 |
public static final String HARDWARE_CONTROLS="android.permission-group.HARDWARE_CONTROLS"; |
374 |
/** Used for permissions that allow access to the user¹s current |
375 |
location. |
376 |
*/ |
377 |
public static final String LOCATION="android.permission-group.LOCATION"; |
378 |
/** Used for permissions that allow an application to send messages |
379 |
on behalf of the user or intercept messages being received by the |
380 |
user. This is primarily intended for SMS/MMS messaging, such as |
381 |
receiving or reading an MMS. |
382 |
*/ |
383 |
public static final String MESSAGES="android.permission-group.MESSAGES"; |
384 |
/** Used for permissions that provide access to networking services. The |
385 |
main permission here is internet access, but this is also an |
386 |
appropriate group for accessing or modifying any network configuration |
387 |
or other related network operations. |
388 |
*/ |
389 |
public static final String NETWORK="android.permission-group.NETWORK"; |
390 |
/** Used for permissions that provide access to the user¹s private data, |
391 |
such as contacts, calendar events, e-mail messages, etc. This includes |
392 |
both reading and writing of this data (which should generally be |
393 |
expressed as two distinct permissions). |
394 |
*/ |
395 |
public static final String PERSONAL_INFO="android.permission-group.PERSONAL_INFO"; |
396 |
/** Used for permissions that are associated with accessing and modifyign |
397 |
telephony state: intercepting outgoing calls, reading |
398 |
and modifying the phone state. Note that |
399 |
placing phone calls is not in this group, since that is in the |
400 |
more important "takin¹ yer moneys" group. |
401 |
*/ |
402 |
public static final String PHONE_CALLS="android.permission-group.PHONE_CALLS"; |
403 |
/** Group of permissions that are related to system APIs. Many |
404 |
of these are not permissions the user will be expected to understand, |
405 |
and such permissions should generally be marked as "normal" protection |
406 |
level so they don¹t get displayed. This can also, however, be used |
407 |
for miscellaneous features that provide access to the operating system, |
408 |
such as writing the global system settings. |
409 |
*/ |
410 |
public static final String SYSTEM_TOOLS="android.permission-group.SYSTEM_TOOLS"; |
411 |
} |
412 |
} |
中文翻译:
程序执行需要读取到安全敏感项必需在androidmanifest.xml中声明相关权限请求, 完整列表如下:
android.permission.ACCESS_CHECKIN_PROPERTIES
允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/write access to the “properties” table in the checkin database, to change values that get uploaded)
android.permission.ACCESS_COARSE_LOCATION
允许一个程序访问CellID或WiFi热点来获取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location)
android.permission.ACCESS_FINE_LOCATION
允许一个程序访问精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location)
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
允许应用程序访问额外的位置提供命令(Allows an application to access extra location provider commands)
android.permission.ACCESS_MOCK_LOCATION
允许程序创建模拟位置提供用于测试(Allows an application to create mock location providers for testing)
android.permission.ACCESS_NETWORK_STATE
允许程序访问有关GSM网络信息(Allows applications to access information about networks)
android.permission.ACCESS_SURFACE_FLINGER
允许程序使用SurfaceFlinger底层特性(Allows an application to use SurfaceFlinger’s low level features)
android.permission.ACCESS_WIFI_STATE
允许程序访问Wi-Fi网络状态信息(Allows applications to access information about Wi-Fi networks)
android.permission.ADD_SYSTEM_SERVICE
允许程序发布系统级服务(Allows an application to publish system-level services).
android.permission.BATTERY_STATS
允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics)
android.permission.BLUETOOTH
允许程序连接到已配对的蓝牙设备(Allows applications to connect to paired bluetooth devices)
android.permission.BLUETOOTH_ADMIN
允许程序发现和配对蓝牙设备(Allows applications to discover and pair bluetooth devices)
android.permission.BRICK
请求能够禁用设备(非常危险)(Required to be able to disable the device (very *erous!).)
android.permission.BROADCAST_PACKAGE_REMOVED
允许程序广播一个提示消息在一个应用程序包已经移除后(Allows an application to broadcast a notification that an application package has been removed)
android.permission.BROADCAST_STICKY
允许一个程序广播常用intents(Allows an application to broadcast sticky intents)
android.permission.CALL_PHONE
允许一个程序初始化一个电话拨号不需通过拨号用户界面需要用户确认(Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.)
android.permission.CALL_PRIVILEGED
允许一个程序拨打任何号码,包含紧急号码无需通过拨号用户界面需要用户确认(Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed)
android.permission.CAMERA
请求访问使用照相设备(Required to be able to access the camera device. )
android.permission.CHANGE_COMPONENT_ENABLED_STATE
允许一个程序是否改变一个组件或其他的启用或禁用(Allows an application to change whether an application component (other than its own) is enabled or not. )
android.permission.CHANGE_CONFIGURATION
允许一个程序修改当前设置,如本地化(Allows an application to modify the current configuration, such as locale. )
android.permission.CHANGE_NETWORK_STATE
允许程序改变网络连接状态(Allows applications to change network connectivity state)
android.permission.CHANGE_WIFI_STATE
允许程序改变Wi-Fi连接状态(Allows applications to change Wi-Fi connectivity state)
android.permission.CLEAR_APP_CACHE
允许一个程序清楚缓存从所有安装的程序在设备中(Allows an application to clear the caches of all installed applications on the device. )
android.permission.CLEAR_APP_USER_DATA
允许一个程序清除用户设置(Allows an application to clear user data)
android.permission.CONTROL_LOCATION_UPDATES
允许启用禁止位置更新提示从无线模块(Allows enabling/disabling location update notifications from the radio. )
android.permission.DELETE_CACHE_FILES
允许程序删除缓存文件(Allows an application to delete cache files)
android.permission.DELETE_PACKAGES
允许一个程序删除包(Allows an application to delete packages)
android.permission.DEVICE_POWER
允许访问底层电源管理(Allows low-level access to power management)
android.permission.DIAGNOSTIC
允许程序RW诊断资源(Allows applications to RW to diagnostic resources. )
android.permission.DISABLE_KEYGUARD
允许程序禁用键盘锁(Allows applications to disable the keyguard )
android.permission.DUMP
允许程序返回状态抓取信息从系统服务(Allows an application to retrieve state dump information from system services.)
android.permission.EXPAND_STATUS_BAR
允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似windows mobile中的托盘程序(Allows an application to expand or collapse the status bar. )
android.permission.FACTORY_TEST
作为一个工厂测试程序,运行在root用户(Run as a manufacturer test application, running as the root user. )
android.permission.FLASHLIGHT
访问闪光灯,android开发网提示htc Dream不包含闪光灯(Allows access to the flashlight )
android.permission.FORCE_BACK
允许程序强行一个后退操作是否在顶层activities(Allows an application to force a BACK operation on whatever is the top activity. )
android.permission.FOTA_UPDATE
暂时不了解这是做什么使用的,android开发网分析可能是一个预留权限.
android.permission.GET_ACCOUNTS
访问一个帐户列表在Accounts Service中(Allows access to the list of accounts in the Accounts Service)
android.permission.GET_PACKAGE_SIZE
允许一个程序获取任何package占用空间容量(Allows an application to find out the space used by any package. )
android.permission.GET_TASKS
允许一个程序获取信息有关当前或最近运行的任务,一个缩略的任务状态,是否活动等等(Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.)
android.permission.HARDWARE_TEST
允许访问硬件(Allows access to hardware peripherals. )
android.permission.INJECT_EVENTS
允许一个程序截获用户事件如按键、触摸、轨迹球等等到一个时间流,android 开发网提醒算是hook技术吧(Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.)
android.permission.INSTALL_PACKAGES
允许一个程序安装packages(Allows an application to install packages. )
android.permission.INTERNAL_SYSTEM_WINDOW
允许打开窗口使用系统用户界面(Allows an application to open windows that are for use by parts of the system user interface. )
android.permission.INTERNET
允许程序打开网络套接字(Allows applications to open network sockets)
android.permission.MANAGE_APP_TOKENS
允许程序管理(创建、催后、 z- order默认向z轴推移)程序引用在窗口管理器中(Allows an application to manage (create, destroy, Z-order) application tokens in the window manager. )
android.permission.MASTER_CLEAR目前还没有明确的解释,android开发网分析可能是清除一切数据,类似硬格机
android.permission.MODIFY_AUDIO_SETTINGS
允许程序修改全局音频设置(Allows an application to modify global audio settings)
android.permission.MODIFY_PHONE_STATE
允许修改话机状态,如电源,人机接口等(Allows modification of the telephony state – power on, mmi, etc. )
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
允许挂载和反挂载文件系统可移动存储(Allows mounting and unmounting file systems for removable storage. )
android.permission.PERSISTENT_ACTIVITY
允许一个程序设置他的activities显示(Allow an application to make its activities persistent. )
android.permission.PROCESS_OUTGOING_CALLS
允许程序监视、修改有关播出电话(Allows an application to monitor, modify, or abort outgoing calls)
android.permission.READ_CALENDAR
允许程序读取用户日历数据(Allows an application to read the user’s calendar data.)
android.permission.READ_CONTACTS
允许程序读取用户联系人数据(Allows an application to read the user’s contacts data.)
android.permission.READ_FRAME_BUFFER
允许程序屏幕波或和更多常规的访问帧缓冲数据(Allows an application to take screen shots and more generally get access to the frame buffer data)
android.permission.READ_INPUT_STATE
允许程序返回当前按键状态(Allows an application to retrieve the current state of keys and switches. )
android.permission.READ_LOGS
允许程序读取底层系统日志文件(Allows an application to read the low-level system log files. )
android.permission.READ_OWNER_DATA
允许程序读取所有者数据(Allows an application to read the owner’s data)
android.permission.READ_SMS
允许程序读取短信息(Allows an application to read SMS messages.)
android.permission.READ_SYNC_SETTINGS
允许程序读取同步设置(Allows applications to read the sync settings)
android.permission.READ_SYNC_STATS
允许程序读取同步状态(Allows applications to read the sync stats)
android.permission.REBOOT
请求能够重新启动设备(Required to be able to reboot the device. )
android.permission.RECEIVE_BOOT_COMPLETED
允许一个程序接收到 ACTION_BOOT_COMPLETED广播在系统完成启动(Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting. )
android.permission.RECEIVE_MMS
允许一个程序监控将收到MMS彩信,记录或处理(Allows an application to monitor incoming MMS messages, to record or perform processing on them. )
android.permission.RECEIVE_SMS
允许程序监控一个将收到短信息,记录或处理(Allows an application to monitor incoming SMS messages, to record or perform processing on them.)
android.permission.RECEIVE_WAP_PUSH
允许程序监控将收到WAP PUSH信息(Allows an application to monitor incoming WAP push messages. )
android.permission.RECORD_AUDIO
允许程序录制音频(Allows an application to record audio)
android.permission.REORDER_TASKS
允许程序改变Z轴排列任务(Allows an application to change the Z-order of tasks)
android.permission.RESTART_PACKAGES
允许程序重新启动其他程序(Allows an application to restart other applications)
android.permission.SEND_SMS
允许程序发送SMS短信(Allows an application to send SMS messages)
android.permission.SET_ACTIVITY_WATCHER
允许程序监控或控制activities已经启动全局系统中Allows an application to watch and control how activities are started globally in the system.
android.permission.SET_ALWAYS_FINISH
允许程序控制是否活动间接完成在处于后台时Allows an application to control whether activities are immediately finished when put in the background.
android.permission.SET_ANIMATION_SCALE
修改全局信息比例(Modify the global animation scaling factor.)
android.permission.SET_DEBUG_APP
配置一个程序用于调试(Configure an application for debugging.)
android.permission.SET_ORIENTATION
允许底层访问设置屏幕方向和实际旋转(Allows low-level access to setting the orientation (actually rotation) of the screen.)
android.permission.SET_PREFERRED_APPLICATIONS
允许一个程序修改列表参数PackageManager.addPackageToPreferred() 和PackageManager.removePackageFromPreferred()方法(Allows an application to modify the list of preferred applications with the PackageManager.addPackageToPreferred() and PackageManager.removePackageFromPreferred() methods.)
android.permission.SET_PROCESS_FOREGROUND
允许程序当前运行程序强行到前台(Allows an application to force any currently running process to be in the foreground.)
android.permission.SET_PROCESS_LIMIT
允许设置最大的运行进程数量(Allows an application to set the maximum number of (not needed) application processes that can be running. )
android.permission.SET_TIME_ZONE
允许程序设置时间区域(Allows applications to set the system time zone)
android.permission.SET_WALLPAPER
允许程序设置壁纸(Allows applications to set the wallpaper )
android.permission.SET_WALLPAPER_HINTS
允许程序设置壁纸hits(Allows applications to set the wallpaper hints)
android.permission.SIGNAL_PERSISTENT_PROCESSES
允许程序请求发送信号到所有显示的进程中(Allow an application to request that a signal be sent to all persistent processes)
android.permission.STATUS_BAR
允许程序打开、关闭或禁用状态栏及图标Allows an application to open, close, or disable the status bar and its icons.
android.permission.SUBSCRIBED_FEEDS_READ
允许一个程序访问订阅RSS Feed内容提供(Allows an application to allow access the subscribed feeds ContentProvider. )
android.permission.SUBSCRIBED_FEEDS_WRITE
系统暂时保留改设置,android开发网认为未来版本会加入该功能。
android.permission.SYSTEM_ALERT_WINDOW
允许一个程序打开窗口使用 TYPE_SYSTEM_ALERT,显示在其他所有程序的顶层(Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. )
android.permission.VIBRATE
允许访问振动设备(Allows access to the vibrator)
android.permission.WAKE_LOCK
允许使用PowerManager的 WakeLocks保持进程在休眠时从屏幕消失( Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming)
android.permission.WRITE_APN_SETTINGS
允许程序写入API设置(Allows applications to write the apn settings)
android.permission.WRITE_CALENDAR
允许一个程序写入但不读取用户日历数据(Allows an application to write (but not read) the user’s calendar data. )
android.permission.WRITE_CONTACTS
允许程序写入但不读取用户联系人数据(Allows an application to write (but not read) the user’s contacts data. )
android.permission.WRITE_GSERVICES
允许程序修改Google服务地图(Allows an application to modify the Google service map. )
android.permission.WRITE_OWNER_DATA
允许一个程序写入但不读取所有者数据(Allows an application to write (but not read) the owner’s data.)
android.permission.WRITE_SETTINGS
允许程序读取或写入系统设置(Allows an application to read or write the system settings. )
android.permission.WRITE_SMS
允许程序写短信(Allows an application to write SMS messages)
android.permission.WRITE_SYNC_SETTINGS
允许程序写入同步设置(Allows applications to write the sync settings)
Android动画编程
本文出自http://wangstar.javaeye.com/blog/409115,感觉基础知识归纳得不错,就COPY下来方便查找。
动画效果编程基础--Android Animation
动画类型
Android的animation由四种类型组成
XML中
alpha
渐变透明度动画效果
scale
渐变尺寸伸缩动画效果
translate
画面转换位置移动动画效果
rotate
画面旋转动画效果
JavaCode中
AlphaAnimation
渐变透明度动画效果
ScaleAnimation
渐变尺寸伸缩动画效果
TranslateAnimation
画面转换位置移动动画效果
RotateAnimation
画面旋转动画效果
Android动画模式
Animation主要有两种动画模式:
一种是tweened animation(渐变动画)
XML中
JavaCode
alpha
AlphaAnimation
scale
ScaleAnimation
一种是frame by frame(画面转换动画)
XML中
JavaCode
translate
TranslateAnimation
rotate
RotateAnimation
如何在XML文件中定义动画
① 打开Eclipse,新建Android工程
② 在res目录中新建anim文件夹
③ 在anim目录中新建一个myanim.xml(注意文件名小写)
④ 加入XML的动画代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha/>
<scale/>
<translate/>
<rotate/>
</set>
复制代码
Android动画解析--XML
<alpha>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="3000" />
<!-- 透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度
toAlpha 属性为动画结束时透明度
说明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字
长整型值:
duration 属性为动画持续时间
说明:
时间以毫秒为单位
-->
</set>
复制代码
<scale>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator=
"@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:startOffset=“700”
android:duration="700" />
</set>
<!-- 尺寸伸缩动画效果 scale
属性:interpolator 指定一个动画的插入器
在我试验过程中,使用android.res.anim中的资源时候发现
有三种动画插入器:
accelerate_decelerate_interpolator 加速-减速 动画插入器
accelerate_interpolator 加速-动画插入器
decelerate_interpolator 减速- 动画插入器
其他的属于特定的动画效果
浮点型值:
fromXScale 属性为动画起始时 X坐标上的伸缩尺寸
toXScale 属性为动画结束时 X坐标上的伸缩尺寸
fromYScale 属性为动画起始时Y坐标上的伸缩尺寸
toYScale 属性为动画结束时Y坐标上的伸缩尺寸
startOffset 属性为从上次动画停多少时间开始执行下个动画
说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置
说明:
以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
布尔型值:
fillAfter 属性 当设置为true ,该动画转化在动画结束后被应用
-->
复制代码
<translate>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="30"
android:toXDelta="-80"
android:fromYDelta="30"
android:toYDelta="300"
android:duration="2000"
/>
<!-- translate 位置转移动画效果
整型值:
fromXDelta 属性为动画起始时 X坐标上的位置
toXDelta 属性为动画结束时 X坐标上的位置
fromYDelta 属性为动画起始时 Y坐标上的位置
toYDelta 属性为动画结束时 Y坐标上的位置
注意:
没有指定fromXType toXType fromYType toYType 时候,
默认是以自己为相对参照物
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
-->
</set>
复制代码
<rotate>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000" />
<!-- rotate 旋转动画效果
属性:interpolator 指定一个动画的插入器
在我试验过程中,使用android.res.anim中的资源时候发现
有三种动画插入器:
accelerate_decelerate_interpolator 加速-减速 动画插入器
accelerate_interpolator 加速-动画插入器
decelerate_interpolator 减速- 动画插入器
其他的属于特定的动画效果
浮点数型值:
fromDegrees 属性为动画起始时物件的角度
toDegrees 属性为动画结束时物件旋转的角度 可以大于360度
说明:
当角度为负数——表示逆时针旋转
当角度为正数——表示顺时针旋转
(负数from——to正数:顺时针旋转)
(负数from——to负数:逆时针旋转)
(正数from——to正数:顺时针旋转)
(正数from——to负数:逆时针旋转)
pivotX 属性为动画相对于物件的X坐标的开始位置
pivotY 属性为动画相对于物件的Y坐标的开始位置
说明: 以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
长整型值:
duration 属性为动画持续时间
说明: 时间以毫秒为单位
-->
</set>
复制代码
如何使用XML中的动画效果
public static Animation loadAnimation (Context context, int id)
//第一个参数Context为程序的上下文
//第二个参数id为动画XML文件的引用
//例子:
myAnimation= AnimationUtils.loadAnimation(this,R.anim.my_action);
//使用AnimationUtils类的静态方法loadAnimation()来加载XML中的动画XML文件
复制代码
如何在Java代码中定义动画
//在代码中定义 动画实例对象
private Animation myAnimation_Alpha;
private Animation myAnimation_Scale;
private Animation myAnimation_Translate;
private Animation myAnimation_Rotate;
//根据各自的构造方法来初始化一个实例对象
myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);
myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
myAnimation_Translate=new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f);
myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f,
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
复制代码
Android动画解析--JavaCode
AlphaAnimation
① AlphaAnimation类对象定义
private AlphaAnimation myAnimation_Alpha;
复制代码
② AlphaAnimation类对象构造
AlphaAnimation(float fromAlpha, float toAlpha)
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);
//说明:
// 0.0表示完全透明
// 1.0表示完全不透明
复制代码
③ 设置动画持续时间
myAnimation_Alpha.setDuration(5000);
//设置时间持续时间为 5000毫秒
复制代码
ScaleAnimation
① ScaleAnimation类对象定义
private AlphaAnimation myAnimation_Alpha;
复制代码
② ScaleAnimation类对象构造
ScaleAnimation(float fromX, float toX, float fromY, float toY,
int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
复制代码
③ 设置动画持续时间
myAnimation_Scale.setDuration(700);
//设置时间持续时间为 700毫秒
复制代码
TranslateAnimation
① TranslateAnimation类对象定义
private AlphaAnimation myAnimation_Alpha;
复制代码
② TranslateAnimation类对象构造
TranslateAnimation(float fromXDelta, float toXDelta,
float fromYDelta, float toYDelta)
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第四个参数toYDelta为动画结束时Y坐标上的移动位置
复制代码
③ 设置动画持续时间
myAnimation_Translate.setDuration(2000);
//设置时间持续时间为 2000毫秒
复制代码
RotateAnimation
① RotateAnimation类对象定义
private AlphaAnimation myAnimation_Alpha;
复制代码
② RotateAnimation类对象构造
RotateAnimation(float fromDegrees, float toDegrees,
int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
//第一个参数fromDegrees为动画起始时的旋转角度
//第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型
//第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型
//第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f,
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
复制代码
③ 设置动画持续时间
myAnimation_Rotate.setDuration(3000);
//设置时间持续时间为 3000毫秒
复制代码
如何使用Java代码中的动画效果
使用从View父类继承过来的方法startAnimation()来为View或是子类View等等添加一个动画效果
MySQL设置当前时间为默认值
下面为您介绍MySQL设置当前时间为默认值的实现全步骤
数据库:test_db1
创建表:test_ta1
字段:
id 编号(自增 且为主键),
createtime 创建日期(默认值为当前时间)
方法一、用alert table语句创建:
- use test_db1;
- create table test_ta1(
- id mediumint(8) unsigned not nulll auto_increment,
- createtime datetime,
- primary key (id)
- )engine=innodb default charset=gbk;
- alert table test_ta1 change createtime createtime timestamp not null default now();
方法二、直接创建:
- use test_db1;
- create table test_ta1(
- id mediumint(8) unsigned not nulll auto_increment,
- createtime timestamp not null default current_timestamp,
- primary key (id)
- )engine=innodb default charset=gbk;
方法三、使用可视化工具(如 mysql-front)创建
右击createtime属性
把Type属性值改为timestamp
default 属性选择<INSERT-TimeStamp>
以上就是MySQL设置当前时间为默认值的方法介绍。
几个JavaScript特效
禁止屏蔽类
1.禁止右键
<body oncontextmenu=return(false)>
2.禁止选择
<body onselectstart="return false">
3.禁止粘贴
<body onpaste="return false">
4.禁止直接访问 [必须框架内才行]
<script>
if (top == self)top.location.href = "page.htm";
</script>
5.禁止frame引用
<script>
if (top != self)top.location.href = "page.htm";
</script>
6.禁止功能键Shift,Alt,Ctrl
<script>function key(){
if(event.shiftKey) alert("Shift不允许使用!");} document.onkeydown=key; </script>
数据取得类
1.取得分辨率
<script>document.write("宽为"+screen.Width+"高为"+screen.Height)</script>
2.取得地址栏
<script>document.write(self.location)</script>
3.取得地址栏后参数
<SCRIPT>var add = top.location;
add = add.toString();
document.write (add.substring(add.indexOf("?")+1,add.length));
</SCRIPT>
常用特效类
1.主页遥控器
文件一.(t1.html)
<SCRIPT language="JavaScript">
window.open("t2.html","_blank","width=200","height=200","scroll=no");
</SCRIPT>
文件二.(t2.html)
<SCRIPT language="JavaScript">
function op(add){if (window.opener){window.opener.document.location = add;}}
</SCRIPT>
<a href=# onClick="op(¹link1.html¹)">地址1 </a><br><a href=# onClick="op(¹link2.html¹)">地址2 </a><br><a href=# onClick="op(¹http://music.jx165.com¹)">地址3 </a>
2.只弹一次的窗口
<script>
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {offset = document.cookie.indexOf(search)
if (offset != -1) {offset += search.length;end = document.cookie.indexOf(";", offset);
if (end == -1)end = document.cookie.length;returnvalue=unescape(document.cookie.substring(offset, end))}
}
return returnvalue;
}
function jx165ad(){
if (get_cookie(¹jx165ad¹)==¹¹){
document.cookie="jx165ad=yes"
window.open("ad.html","_blank","width=200","height=200","scroll=no");
}
else {}
}
</script>
<body>
<script>
jx165ad();
</script>
3.鼠标放在连接上强行点击
<script>
function mClk2() {var source=event.srcElement;if (source.tagName=="A"){source.click();self.focus();}}
document.write("<div onmouseover=mClk2();>");
</script>
PHP正则表达式的使用技巧
PHP正则表达式主要用于字符串的模式分割、匹配、查找及替换操作。使用正则表达式在某些简单的环境下可能效率不高,因此如何更好的使用PHP正则表达式需要综合考虑。
PHP正则表达式的定义:
用于描述字符排列和匹配模式的一种语法规则。它主要用于字符串的模式分割、匹配、查找及替换操作。
PHP中的正则函数:
PHP中有两套正则函数,两者功能差不多,分别为:
一套是由PCRE(Perl Compatible Regular Expression)库提供的。使用“preg_”为前缀命名的函数;
一套由POSIX(Portable Operating System Interface of Unix )扩展提供的。使用以“ereg_”为前缀命名的函数;(POSIX的正则函数库,自PHP 5.3以后,就不在推荐使用,从PHP6以后,就将被移除)
由于POSIX正则即将推出历史舞台,并且PCRE和perl的形式差不多,更利于我们在perl和php之间切换,所以这里重点介绍PCRE正则的使用。
PCRE正则表达式
PCRE全称为Perl Compatible Regular Expression,意思是Perl兼容正则表达式。
在PCRE中,通常将模式表达式(即正则表达式)包含在两个反斜线“/”之间,如“/apple/”。
正则中重要的几个概念有:元字符、转义、模式单元(重复)、反义、引用和断言,这些概念都可以在文章[1]中轻松的理解和掌握。
常用的元字符(Meta-character):
元字符 说明
A 匹配字符串串首的原子
匹配字符串串尾的原子
匹配单词的边界 /is/ 匹配头为is的字符串 /is/ 匹配尾为is的字符串 /is/ 定界
B 匹配除单词边界之外的任意字符 /Bis/ 匹配单词“This”中的“is”
d 匹配一个数字;等价于[0-9]
D 匹配除数字以外任何一个字符;等价于[^0-9]
w 匹配一个英文字母、数字或下划线;等价于[0-9a-zA-Z_]
W 匹配除英文字母、数字和下划线以外任何一个字符;等价于[^0-9a-zA-Z_]
s 匹配一个空白字符;等价于[f v]
S 匹配除空白字符以外任何一个字符;等价于[^f v]
f 匹配一个换页符等价于 x0c 或 cL
匹配一个换行符;等价于 x0a 或 cJ
匹配一个回车符等价于x0d 或 cM
匹配一个制表符;等价于 x09或\cl
v 匹配一个垂直制表符;等价于x0b或ck
oNN 匹配一个八进制数字
xNN 匹配一个十六进制数字
cC 匹配一个控制字符
模式修正符(Pattern Modifiers):
模式修正符在忽略大小写、匹配多行中使用特别多,掌握了这一个修正符,往往能解决我们遇到的很多问题。
i -可同时匹配大小写字母
M -将字符串视为多行
S -将字符串视为单行,换行符做普通字符看待,使“.”匹配任何字符
X -模式中的空白忽略不计
U -匹配到最近的字符串
e -将替换的字符串作为表达使用
格式:/apple/i匹配“apple”或“Apple”等,忽略大小写。 /i
PCRE的模式单元:
//1 提取第一位的属性
/^d{2} ([W])d{2}\1d{4}$匹配“12-31-2006”、“09/27/1996”、“86 01 4321”等字符串。但上述正则表达式不匹配“12/34-5678”的格式。这是因为模式“[W]”的结果“/”已经被存储。下个位置“1”引用 时,其匹配模式也是字符“/”。
当不需要存储匹配结果时使用非存储模式单元“(?:)”
例如/(?:a|b|c)(D|E|F)\1g/ 将匹配“aEEg”。在一些正则表达式中,使用非存储模式单元是必要的。否则,需要改变其后引用的顺序。上例还可以写成/(a|b|c)(C|E|F)2g/。
PCRE正则表达式函数:
| preg_match()和preg_match_all() preg_quote() preg_split() preg_grep() preg_replace() |
函数的具体使用,我们可以通过PHP手册来找到,下面分享一些平时积累的正则表达式:
匹配action属性
| $str = ¹¹; $match = ¹¹; preg_match_all(¹/s+action="(?!http:)(.*?)"s/¹, $str, $match); print_r($match); |
在正则中使用回调函数
| /** * replace some string by callback function * */ function callback_replace() { $url = ¹http://esfang.house.sina.com.cn¹; $str = ¹¹; $str = preg_replace ( ¹/(?<=saction=")(?!http:)(.*?)(?="s)/e¹, ¹search($url, \1)¹, $str ); echo $str; } function search($url, $match){ return $url . ¹/¹ . $match; } |
带断言的正则匹配
| $match = ¹¹; $str = ¹xxxxxx.com.cn bold font paragraph text ¹; preg_match_all ( ¹/(?<=<(w{1})>).*(?=</1>)/¹, $str, $match ); echo "匹配没有属性的HTML标签中的内容:"; print_r ( $match ); |
替换HTML源码中的地址
| $form_html = preg_replace ( ¹/(?<=saction="|ssrc="|shref=")(?!http:|javascript)(.*?)(?="s)/e¹, ¹add_url($url, ¹\1¹)¹, $form_html ); |
正则工具虽然强大,但是从效率和编写时间上来讲,有时可能没有explode来的直接,对于一些紧急或者要求不高的任务,简单、粗暴的方法也许更好。
对于preg和ereg之间的执行效率,曾看到文章说preg要更快一点,具体由于使用ereg的时候并不多,而且也要推出历史舞台了,再加个个人更偏好于PCRE的方式。
21个实用的PHP代码
1. PHP可阅读随机字符串
此代码将创建一个可阅读的字符串,使其更接近词典中的单词,实用且具有密码验证功能。
| /************** *@length - length of random string (must be a multiple of 2) **************/ function readable_random_string($length = 6){ $conso=array("b","c","d","f","g","h","j","k","l", "m","n","p","r","s","t","v","w","x","y","z"); $vocal=array("a","e","i","o","u"); $password=""; srand ((double)microtime()*1000000); $max = $length/2; for($i=1; $i<=$max; $i++) { $password.=$conso[rand(0,19)]; $password.=$vocal[rand(0,4)]; } return $password; } |
2. PHP生成一个随机字符串
如果不需要可阅读的字符串,使用此函数替代,即可创建一个随机字符串,作为用户的随机密码等。
| /************* *@l - length of random string */ function generate_rand($l){ $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; srand((double)microtime()*1000000); for($i=0; $i<$l; $i++) { $rand.= $c[rand()%strlen($c)]; } return $rand; } |
3. PHP编码电子邮件地址
使用此代码,可以将任何电子邮件地址编码为 html 字符实体,以防止被垃圾邮件程序收集。
| function encode_email($email=¹info@domain.com¹, $linkText=¹Contact Us¹, $attrs =¹class="emailencoder"¹ ) { // remplazar aroba y puntos $email = str_replace(¹@¹, ¹@¹, $email); $email = str_replace(¹.¹, ¹.¹, $email); $email = str_split($email, 5); $linkText = str_replace(¹@¹, ¹@¹, $linkText); $linkText = str_replace(¹.¹, ¹.¹, $linkText); $linkText = str_split($linkText, 5); $part1 = ¹<a href="ma¹; $part2 = ¹ilto:¹; $part3 = ¹" ¹. $attrs .¹ >¹; $part4 = ¹</a>¹; $encoded = ¹<script type="text/javascript">¹; $encoded .= "document.write(¹$part1¹);"; $encoded .= "document.write(¹$part2¹);"; foreach($email as $e) { $encoded .= "document.write(¹$e¹);"; } $encoded .= "document.write(¹$part3¹);"; foreach($linkText as $l) { $encoded .= "document.write(¹$l¹);"; } $encoded .= "document.write(¹$part4¹);"; $encoded .= ¹</script>¹; return $encoded; } |
4. PHP验证邮件地址
电子邮件验证也许是中最常用的网页表单验证,此代码除了验证电子邮件地址,也可以选择检查邮件域所属 DNS 中的 MX 记录,使邮件验证功能更加强大。
| function is_valid_email($email, $test_mx = false) { if(eregi("^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})$", $email)) if($test_mx) { list($username, $domain) = split("@", $email); return getmxrr($domain, $mxrecords); } else return true; else return false; } |
5. PHP列出目录内容
| function list_files($dir) { if(is_dir($dir)) { if($handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != "." && $file != ".." && $file != "Thumbs.db") { echo ¹<a target="_blank" href="¹.$dir.$file.¹">¹.$file.¹</a><br>¹." "; } } closedir($handle); } } } |
6. PHP销毁目录
删除一个目录,包括它的内容。
| /***** *@dir - Directory to destroy *@virtual[optional]- whether a virtual directory */ function destroyDir($dir, $virtual = false) { $ds = DIRECTORY_SEPARATOR; $dir = $virtual ? realpath($dir) : $dir; $dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir; if (is_dir($dir) && $handle = opendir($dir)) { while ($file = readdir($handle)) { if ($file == ¹.¹ || $file == ¹..¹) { continue; } elseif (is_dir($dir.$ds.$file)) { destroyDir($dir.$ds.$file); } else { unlink($dir.$ds.$file); } } closedir($handle); rmdir($dir); return true; } else { return false; } } |
7. PHP解析 JSON 数据
与大多数流行的 Web 服务如 twitter 通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据的各种传送格式,包括 JSON,XML 等等。
| $json_string=¹{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} ¹; $obj=json_decode($json_string); echo $obj->name; //prints foo echo $obj->interest[1]; //prints php |
8. PHP解析 XML 数据
| //xml string $xml_string="<?xml version=¹1.0¹?> <users> <user id=¹398¹> <name>Foo</name> <email>foo@bar.com</name> </user> <user id=¹867¹> <name>Foobar</name> <email>foobar@foo.com</name> </user> </users>"; //load the xml string using simplexml $xml = simplexml_load_string($xml_string); //loop through the each node of user foreach ($xml->user as $user) { //access attribute echo $user[¹id¹], ¹ ¹; //subnodes are accessed by -> operator echo $user->name, ¹ ¹; echo $user->email, ¹<br />¹; } |
9. PHP创建日志缩略名
创建用户友好的日志缩略名。
| function create_slug($string){ $slug=preg_replace(¹/[^A-Za-z0-9-]+/¹, ¹-¹, $string); return $slug; } |
10. PHP获取客户端真实 IP 地址
该函数将获取用户的真实 IP 地址,即便他使用代理服务器。
| function getRealIpAddr() { if (!emptyempty($_SERVER[¹HTTP_CLIENT_IP¹])) { $ip=$_SERVER[¹HTTP_CLIENT_IP¹]; } elseif (!emptyempty($_SERVER[¹HTTP_X_FORWARDED_FOR¹])) //to check ip is pass from proxy { $ip=$_SERVER[¹HTTP_X_FORWARDED_FOR¹]; } else { $ip=$_SERVER[¹REMOTE_ADDR¹]; } return $ip; } |
11. PHP强制性文件下载
为用户提供强制性的文件下载功能。
| /******************** *@file - path to file */ function force_download($file) { if ((isset($file))&&(file_exists($file))) { header("Content-length: ".filesize($file)); header(¹Content-Type: application/octet-stream¹); header(¹Content-Disposition: attachment; filename="¹ . $file . ¹"¹); readfile("$file"); } else { echo "No file selected"; } } |
12. PHP创建标签云
| function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 ) { $minimumCount = min( array_values( $data ) ); $maximumCount = max( array_values( $data ) ); $spread = $maximumCount - $minimumCount; $cloudHTML = ¹¹; $cloudTags = array(); $spread == 0 && $spread = 1; foreach( $data as $tag => $count ) { $size = $minFontSize + ( $count - $minimumCount ) * ( $maxFontSize - $minFontSize ) / $spread; $cloudTags[] = ¹<a style="font-size: ¹ . floor( $size ) . ¹px¹ . ¹" href="#" title="¹¹ . $tag . ¹¹ returned a count of ¹ . $count . ¹">¹ . htmlspecialchars( stripslashes( $tag ) ) . ¹</a>¹; } return join( " ", $cloudTags ) . " "; } /************************** **** Sample usage ***/ $arr = Array(¹Actionscript¹ => 35, ¹Adobe¹ => 22, ¹Array¹ => 44, ¹Background¹ => 43, ¹Blur¹ => 18, ¹Canvas¹ => 33, ¹Class¹ => 15, ¹Color Palette¹ => 11, ¹Crop¹ => 42, ¹Delimiter¹ => 13, ¹Depth¹ => 34, ¹Design¹ => 8, ¹Encode¹ => 12, ¹Encryption¹ => 30, ¹Extract¹ => 28, ¹Filters¹ => 42); echo getCloud($arr, 12, 36); |
13. PHP寻找两个字符串的相似性
PHP 提供了一个极少使用的 similar_text 函数,但此函数非常有用,用于比较两个字符串并返回相似程度的百分比。
| similar_text($string1, $string2, $percent); //$percent will have the percentage of similarity |
14. PHP在应用程序中使用 Gravatar 通用头像
随着 WordPress 越来越普及,Gravatar 也随之流行。由于 Gravatar 提供了易于使用的 API,将其纳入应用程序也变得十分方便。
| /****************** *@email - Email address to show gravatar for *@size - size of gravatar *@default - URL of default gravatar to use *@rating - rating of Gravatar(G, PG, R, X) */ function show_gravatar($email, $size, $default, $rating) { echo ¹<img src="http://www.gravatar.com/avatar.php?gravatar_id=¹.md5($email). ¹&default=¹.$default.¹&size=¹.$size.¹&rating=¹.$rating.¹" width="¹.$size.¹px" height="¹.$size.¹px" />¹; } |
15. PHP在字符断点处截断文字
所谓断字 (word break),即一个单词可在转行时断开的地方。这一函数将在断字处截断字符串。
| // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; } /***** Example ****/ $short_string=myTruncate($long_string, 100, ¹ ¹); |
16. PHP文件 Zip 压缩
| /* creates a compressed zip file */ function create_zip($files = array(),$destination = ¹¹,$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo ¹The zip archive contains ¹,$zip->numFiles,¹ files with a status of ¹,$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } } /***** Example Usage ***/ $files=array(¹file1.jpg¹, ¹file2.jpg¹, ¹file3.gif¹); create_zip($files, ¹myzipfile.zip¹, true); |
17. PHP解压缩 Zip 文件
| /********************** *@file - path to zip file *@destination - destination directory for unzipped files */ function unzip_file($file, $destination){ // create object $zip = new ZipArchive() ; // open archive if ($zip->open($file) !== TRUE) { die (’Could not open archive’); } // extract contents to destination directory $zip->extractTo($destination); // close archive $zip->close(); echo ¹Archive extracted to directory¹; } |
18. PHP为 URL 地址预设 http 字符串
有时需要接受一些表单中的网址输入,但用户很少添加 http:// 字段,此代码将为网址添加该字段。
| if (!preg_match("/^(http|ftp):/", $_POST[¹url¹])) { $_POST[¹url¹] = ¹http://¹.$_POST[¹url¹]; } |
19. PHP将网址字符串转换成超级链接
该函数将 URL 和 E-mail 地址字符串转换为可点击的超级链接。
|
20. PHP调整图像尺寸
创建图像缩略图需要许多时间,此代码将有助于了解缩略图的逻辑。
| /********************** *@filename - path to the image *@tmpname - temporary path to thumbnail *@xmax - max width *@ymax - max height */ function resize_image($filename, $tmpname, $xmax, $ymax) { $ext = explode(".", $filename); $ext = $ext[count($ext)-1]; if($ext == "jpg" || $ext == "jpeg") $im = imagecreatefromjpeg($tmpname); elseif($ext == "png") $im = imagecreatefrompng($tmpname); elseif($ext == "gif") $im = imagecreatefromgif($tmpname); $x = imagesx($im); $y = imagesy($im); if($x <= $xmax && $y <= $ymax) return $im; if($x >= $y) { $newx = $xmax; $newy = $newx * $y / $x; } else { $newy = $ymax; $newx = $x / $y * $newy; } $im2 = imagecreatetruecolor($newx, $newy); imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y); return $im2; } |
21. PHP检测 ajax 请求
大多数的 JavaScript 框架如 jquery,Mootools 等,在发出 Ajax 请求时,都会发送额外的 HTTP_X_REQUESTED_WITH 头部信息,头当他们一个ajax请求,因此你可以在服务器端侦测到 Ajax 请求。
| if(!emptyempty($_SERVER[¹HTTP_X_REQUESTED_WITH¹]) && strtolower($_SERVER[¹HTTP_X_REQUESTED_WITH¹]) == ¹xmlhttprequest¹){ //If AJAX Request Then }else{ //something else } |
英文原稿:21 Really Useful & Handy PHP Code Snippets | Web Developer Plus
PHP加密解密算法
最近学习URL跳转的时候新进三个超好用的PHP加密解密函数,貌似是discuz里的…使用这些加密解密的原因是因为有时自己的URL地址被人获取以后想破解你里面传值的内容就必须知道你的key,没有key,他应该要破了一阵子才能知道你URL里面的内容吧。
将它们打包成一个文件就叫fun.php吧
<?php
function passport_encrypt($txt, $key) {
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = ¹¹;
for($i = 0;$i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
}
return base64_encode(passport_key($tmp, $key));
}
function passport_decrypt($txt, $key) {
$txt = passport_key(base64_decode($txt), $key);
$tmp = ¹¹;
for($i = 0;$i < strlen($txt); $i++) {
$md5 = $txt[$i];
$tmp .= $txt[++$i] ^ $md5;
}
return $tmp;
}
function passport_key($txt, $encrypt_key) {
$encrypt_key = md5($encrypt_key);
$ctr = 0;
$tmp = ¹¹;
for($i = 0; $i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
}
return $tmp;
}
?>
以下一些示例加深对这三个加密解密函数的理解
//string.php
<?php
include “fun.php”;
$txt = “This is a test”;
$key = “testkey”;
$encrypt = passport_encrypt($txt,$key);
$decrypt = passport_decrypt($encrypt,$key);
echo $txt.”<br><hr>”;
echo $encrypt.”<br><hr>”;
echo $decrypt.”<br><hr>”;
?>
//array.php
<?php
include “fun.php”;
$array = array(
"a" => "1",
"b" => "2",
"c" => "3",
"d" => "4"
);
//serialize产生一个可存储的值,返回一个字符串,unserialize还原
$txt = serialize($array);
$key = “testkey”;
$encrypt = passport_encrypt($txt,$key);
$decrypt = passport_decrypt($encrypt,$key);
$decryptArray = unserialize($decrypt);
echo $txt.”<br><hr>”;
echo $encrypt.”<br><hr>”;
echo $decrypt.”<br><hr>”;
echo $decryptArray.”<br><hr>”;
?>
关键的地方来了当你要跳转到另外一个网址,但又要保证你的session无误的时候,你需要对session作一个处理.貌似一个公司有一个网站又有一个论坛,两个地方都有注册和登录,但又不想让用户在主页登录后跳转到论坛的时候session失效,即是登录一次跑完整间公司
那要怎样来处理用户的session呢
网页都是无状态的,如果要在新的网页中继续使用session,则需要把session从一个地方移到另一个地方,可能有些人已经想到了,我可以通过url传址的方式来调用它.而PHP有个处理session的变量,叫$_SESSION.于是将需要注册的session转换成一个数组吧.那么,你可以这样写:
//login.php
<?php
session_start();
include “fun.php”;
$_SESSION[“userid”];
$_SESSION[“username”];
$_SESSION[“userpwd”];
header("Location: http://$domain/process.php?s=".urlencode(passport_encrypt(serialize($_SESSION),"sessionkey")));
?>
上例中先用serialize将$_SESSION变成可存储的数据,然后通过passport_encrypt将这个数据加密,加urlencode的原因是因为$_SESSION加密时,有可能会产生像料想不到的编码,所以以防万一(事实证明非常有效)
处理下
//process.php
<?php
session_start();
include “fun.php”;
$_SESSION=unserialize(passport_decrypt($_GET["s"],"sessionkey"));
header("Location: http://$domain/index.php");
?>
先用$_GET[“s”]获取URL的参数,然后用passport_decrypt将其解密,再用unserialize将其数据还原成原始数据,到了这步处理,你的网页就可能通过header自由跳转啦。
这种方法还涉及到安全性的问题,如果你的url地址在传址的过程中被人家获取的话,那就真的是不好意思了人家虽然可能破解不了url里边的内容,但人家也可以直接用这个url地址来登录你的一些个人账户啊,邮箱帐户啊甚至银行帐户(当然很少人会这样写,我例外,哈哈)听起来好怕.但其实你可以在跳转页面作取消session处理.
以下是加强版的process.php
<?php
session_start();
include_once "fun.php";
$_SESSION=unserialize(passport_decrypt($_GET["s"],"sessionkey"));
if((time()-$_SESSION["TIME"])>30){
header("Location: http://$domain/ login.php");
unset($_SESSION["USERNAME"]);
unset($_SESSION["PASSWORD"]);
}
else
header("Location: http://$domain/ index.php");
?>
写这个文件之前,你还要在登录那边设置
$_SESSION["TIME"] = time();
设置这个的原因主要是获取两边的时间,如果跳转的时候超过30秒的时候,你就可以让它跳转到login.php登录页面,网速慢的客户就不好意思啦但这也预防了如果此url被人获取,而这个人又没有在30秒内登录的话,那就不好意思啊,超时重新登录.
$_SESSION["USERNAME"]和$_SESSION["PASSWORD"] 这两个东东就是用户登录时需要输入的用户名和密码了.取消这两个session的原因就是因为如果你的url被人获取了,那个人虽然在超过30秒内跳转到loign.php的页面,但那些传过来的session依然有效,只要将url后缀login.php改为index.php.那他一样登录成功。
JSP中用Session实现在线用户统计
作为一个程序员,你可以不介意具体在客户端是如何实现,就方便的实现简单的基于session的用户管理。现在对于处理在线用户,有几种不同的处理方法。
一种是页面刷新由用户控制,服务器端控制一个超时时间比如30分钟,到了时间之后用户没有动作就被踢出。这种方法的优点是,如果用户忘了退出,可以防止别人恶意操作。缺点是,如果你在做一件很耗时间的事情,超过了这个时间限制,submit的时候可能要再次面临登陆。如果原来的叶面又是强制失效的话,就有可能丢失你做的工作。在实现的角度来看,这是最简单的,Server端默认实现的就是这样的模式。
另一种方式是,站点采用框架结构,有一个Frame或者隐藏的iframe在不断刷新,这样你永远不会被踢出,但是服务器端为了判断你是否在线,需要定一个发呆时间,如果超过这个发呆时间你除了这个自动刷新的页面外没有刷新其他页面的话,就认为你已经不在线了。采取这种方式的典型是xici.net。 他的优点是可以可以利用不断的刷新实现一些类似server-push的功能,比如网友之间发送消息。
不管哪一种模式,为了实现浏览当前所有的在线用户,还需要做一些额外的工作。Servlet API中没有得到Session列表的API。
可以利用的是Listener. Servlet 2.2和2.3规范在这里略微有一些不一样。2.2中HttpSessionBindingListener可以实现当一个HTTPSession中的Attribute变化的时候通知你的类。而2.3中还引入了HttpSessionAttributeListener.鉴于我使用的环境是Visual age for Java 4和JRun server 3.1,他们还不直接支持Servlet 2.3的编程,这里我用的是HttpSessionBindingListener.
需要做的事情包括做一个新的类来实现HttpSessionBindingListener接口。这个接口有两个方法:
public void valueBound(HttpSessionBindingEvent event)
public void valueUnbound(HttpSessionBindingEvent event)
当你执行Session.addAttribute(String,Object)的时候,如果你已经把一个实现了HttpSessionBindingListener接口的类加入为Attribute,Session会通知你的类,调用你的valueBound方法。相反,Session.removeAttribute方法对应的是valueUndound方法。
public class HttpSessionBinding implements javax.servlet.http.HttpSessionBindingListener
{
ServletContext application = null;
public HttpSessionBinding(ServletContext application)
{
super();
if (application ==null)
throw new IllegalArgumentException("Null application is not accept.");
this.application = application;
}
public void valueBound(javax.servlet.http.HttpSessionBindingEvent e)
{
Vector activeSessions = (Vector) application.getAttribute("activeSessions");
if (activeSessions == null)
{
activeSessions = new Vector();
}
JDBCUser sessionUser = (JDBCUser)e.getSession().getAttribute("user");
if (sessionUser != null)
{
activeSessions.add(e.getSession());
}
application.setAttribute("activeSessions",activeSessions);
}
public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent e)
{
JDBCUser sessionUser = (JDBCUser)e.getSession().getAttribute("user");
if (sessionUser == null)
{
Vector activeSessions = (Vector) application.getAttribute("activeSessions");
if (activeSessions != null)
{
activeSessions.remove(e.getSession().getId());
application.setAttribute("activeSessions",activeSessions);
}
}
}
}
假设其中的JDBCUser类是一个任意User类。在执行用户登录时,把User类和HttpSessionBinding类都加入到Session中去。
这样,每次用户登录后,在application中的attribute "activeSessions"这个vector中都会增加一条记录。每当session超时,valueUnbound被触发,在这个vector中删去将要被超时的session.
public void login()
throws ACLException,SQLException,IOException
{
/* get JDBC User Class */
if (user != null)
{
logout();
}
{
// if session time out, or user didn¹t login, save the target url temporary.
JDBCUserFactory uf = new JDBCUserFactory();
if ( (this.request.getParameter("userID")==null) || (this.request.getParameter("password")==null) )
{
throw new ACLException("Please input a valid userName and password.");
}
JDBCUser user = (JDBCUser) uf.UserLogin(
this.request.getParameter("userID"),
this.request.getParameter("password") );
user.touchLoginTime();
this.session.setAttribute("user",user);
this.session.setAttribute("BindingNotify",new HttpSessionBinding(application));
}
}
Login的时候,把User和这个BindingNotofy目的的类都加入到session中去。logout的时候,就要主动在activeSessions这个vector中删去这个session.
public void logout()
throws SQLException,ACLException
{
if (this.user == null && this.session.getAttribute("user")==null)
{
return;
}
Vector activeSessions = (Vector) this.application.getAttribute("activeSessions");
if (activeSessions != null)
{
activeSessions.remove(this.session);
application.setAttribute("activeSessions",activeSessions);
}
java.util.Enumeration e = this.session.getAttributeNames();
while (e.hasMoreElements())
{
String s = (String)e.nextElement();
this.session.removeAttribute(s);
}
this.user.touchLogoutTime();
this.user = null;
}
这两个函数位于一个HttpSessionManager类中.这个类引用了jsp里面的application全局对象。这个类的其他代码和本文无关且相当长,我就不贴出来了。
下面来看看JSP里面怎么用。
假设一个登录用的表单被提交到doLogin.jsp, 表单中包含UserName和password域。节选部分片段:
<%
HttpSessionManager hsm = new HttpSessionManager(application,request,response);
try
{
hsm.login();
}
catch ( UserNotFoundException e)
{
response.sendRedirect("InsufficientPrivilege.jsp?detail=User%20does%20not%20exist.");
return;
}
catch ( InvalidPasswordException e2)
{
response.sendRedirect("InsufficientPrivilege.jsp?detail=Invalid%20Password");
return;
}
catch ( Exception e3)
{
%> Error:<%=e3.toString() %><br>
Press <a href="login.jsp">Here</a> to relogin.
<% return;
}
response.sendRedirect("index.jsp");
%>
再来看看现在我们怎么得到一个当前在线的用户列表。
<body bgcolor="#FFFFFF">
<table cellspacing="0" cellpadding="0" width="100%">
<tr >
<td style="width:24px">SessionId
</td>
<td style="width:80px" >User
</td>
<td style="width:80px" >Login Time
</td>
<td style="width:80px" >Last Access Time
</td>
</tr>
<%
Vector activeSessions = (Vector) application.getAttribute("activeSessions");
if (activeSessions == null)
{
activeSessions = new Vector();
application.setAttribute("activeSessions",activeSessions);
}
Iterator it = activeSessions.iterator();
while (it.hasNext())
{
HttpSession sess = (HttpSession)it.next();
JDBCUser sessionUser = (JDBCUser)sess.getAttribute("user");
String userId = (sessionUser!=null)?sessionUser.getUserID():"None";
%>
<tr>
<td nowrap=¹¹><%= sess.getId() %></td>
<td nowrap=¹¹><%= userId %></td>
<td nowrap=¹¹>
<%= BeaconDate.getInstance( new Java.util.Date(sess.getCreationTime())).getDateTimeString()%></td>
<td class="<%= stl %>3" nowrap=¹¹>
<%= BeaconDate.getInstance( new java.util.Date(sess.getLastAccessedTime())).getDateTimeString()%></td>
</tr>
<%
}
%>
</table>
</body>
以上的代码从application中取出activeSessions,并且显示出具体的时间。其中BeaconDate类假设为格式化时间的类。
这样,我们得到了一个察看在线用户的列表的框架。至于在线用户列表分页等功能,与本文无关,不予讨论。
这是一个非刷新模型的例子,依赖于session的超时机制。我的同事sonymusic指出很多时候由于各个厂商思想的不同,这有可能是不可信赖的。考虑到这种需求,需要在每个叶面刷新的时候都判断当前用户距离上次使用的时间是否超过某一个预定时间值。这实质上就是自己实现session超时。如果需要实现刷新模型,就必须使用这种每个叶面进行刷新判断的方法。
Java中汉字编码讲解
1. 问题的起源
每个国家(或区域)都规定了计算机信息交换用的字符编码集,如美国的扩展 ASCII码, 中国的 GB2312-80,日本的 JIS 等,作为该国家/区域内信息处理的基础,有着统一编码的重要作用。字符编码集按长度分为 SBCS(单字节字符集),DBCS(双字节字符集)两大类。早期的软件(尤其是操作系统),为了解决本地字符信息的计算机处理,出现了各种本地化版本(L10N),为了区分,引进了 LANG, Codepage 等概念。但是由于各个本地字符集代码范围重叠,相互间信息交换困难;软件各个本地化版本独立维护成本较高。因此有必要将本地化工作中的共性抽取出来,作一致处理,将特别的本地化处理内容降低到最少。这也就是所谓的国际化(I18N)。各种语言信息被进一步规范为 Locale 信息。处理的底层字符集变成了几乎包含了所有字形的 Unicode。
现在大部分具有国际化特征的软件核心字符处理都是以 Unicode 为基础的,在软件运行时根据当时的 Locale/Lang/Codepage 设置确定相应的本地字符编码设置,并依此处理本地字符。在处理过程中需要实现 Unicode 和本地字符集的相互转换,甚或以 Unicode 为中间的两个不同本地字符集的相互转换。这种方式在网络环境下被进一步延伸,任何网络两端的字符信息也需要根据字符集的设置转换成可接受的内容。
Java 语言是用 Unicode 表示字符的,遵守 Unicode V2.0。Java 程序无论是从/往文件系统以字符流读/写文件,还是往 URL 连接写 HTML 信息,或从 URL 连接读取参数值,都会有字符编码的转换。这样做虽然增加了编程的复杂度,容易引起混淆,但却是符合国际化的思想的。
从理论上来说,这些根据字符集设置而进行的字符转换不应该产生太多问题。事实是由于应用程序的实际运行环境不同,Unicode 和各个本地字符集的补充、完善,以及系统或应用程序实现的不规范,转码时出现的问题时时困扰着程序员和用户。
2. GB2312-80,GBK,GB18030-2000 汉字字符集及 Encoding
其实解决 JAVA 程序中的汉字编码问题的方法往往很简单,但理解其背后的原因,定位问题,还需要了解现有的汉字编码和编码转换。
GBK 是 GB2312-80 的扩展,是向上兼容的。它包含了 20902 个汉字,其编码范围是 0x8140-0xfefe,剔除高位 0x80 的字位。其所有字符都可以一对一映射到 Unicode 2.0,也就是说 JAVA 实际上提供了 GBK 字符集的支持。这是现阶段 Windows 和其它一些中文操作系统的缺省字符集,但并不是所有的国际化软件都支持该字符集,感觉是他们并不完全知道 GBK 是怎么回事。值得注意的是它不是国家标准,而只是规范。随着 GB18030-2000国标的发布,它将在不久的将来完成它的历史使命。
GB2312-80 是在国内计算机汉字信息技术发展初始阶段制定的,其中包含了大部分常用的一、二级汉字,和 9 区的符号。该字符集是几乎所有的中文系统和国际化的软件都支持的中文字符集,这也是最基本的中文字符集。其编码范围是高位0xa1-0xfe,低位也是 0xa1-0xfe;汉字从 0xb0a1 开始,结束于 0xf7fe;
GB18030-2000(GBK2K) 在 GBK 的基础上进一步扩展了汉字,增加了藏、蒙等少数民族的字形。GBK2K 从根本上解决了字位不够,字形不足的问题。它有几个特点,
它并没有确定所有的字形,只是规定了编码范围,留待以后扩充。
编码是变长的,其二字节部分与 GBK 兼容;四字节部分是扩充的字形、字位,其编码范围是首字节 0x81-0xfe、二字节0x30-0x39、三字节 0x81-0xfe、四字节0x30-0x39。
它的推广是分阶段的,首先要求实现的是能够完全映射到 Unicode 3.0 标准的所有字形。
它是国家标准,是强制性的。
现在还没有任何一个操作系统或软件实现了 GBK2K 的支持,这是现阶段和将来汉化的工作内容。
Unicode 的介绍......就免了吧。
JAVA 支持的encoding中与中文编程相关的有:(有几个在JDK文档中未列出)
ASCII 7-bit, 同 ascii7
20个网页制作技巧
1)怎样将 Dreamweaver 集成到 IE 浏览器?
Dreamweaver 安装程序会在上下文选单增加一个“ Edit with Dreamweaver ”命令,我们还可以修改 Windows 的注册表使它与 IE 集成。就象 MS Word 、 Frontpage 和 Notepad 一样,通过 IE 工具栏的编辑按钮来调用 Dreamweaver 打开当前网页。
将下面文本的最后一行要改为你自己的 Dreamweaver 安装路径,把它们保存为一个 *.reg 文件,双击它将信息添加到注册表即可。
REGEDIT4
[HKEY_CLASSES_ROOT.htmOpenWithListDreamweaver]
[HKEY_CLASSES_ROOT.htmOpenWithListDreamweavershell]
[HKEY_CLASSES_ROOT.htmOpenWithListDreamweavershelledit]
[HKEY_CLASSES_ROOT.htmOpenWithListDreamweavershelleditcommand]
@="C:Program filesMacromediaDreamweaver 3dreamweaver.exe %1"
如果要设置为 IE 缺省的编辑器,打开 IE 的“Internet 选项”,在程序标签指定。
2)为了使用某些脚本,经常要为图形或文本加上空链接,但是浏览时点击有空链接的对象时,会跳到页面的顶端,如何避免?
因为浏览器以为链接到同一页,可它又找不到定义的书签( anchor ),于是停留在页面的顶端。用“ javascript:void(null) ”替换空链接的“ # ”,解决这个问题。
3)使用 CSS 、层的时候,在不同浏览器的效果不一样,有时甚至出现错位现象,怎样解决?
在对不同浏览器的兼容方面, Dreamweaver 作得不错,但绝不意味用 Dreamweaver 作出的网页在 IE 和 Netscape 中完全一样。通常情况下,用不同的浏览器浏览同一个网页的外观不可能完全一样,这是不同厂家的浏览器本身决定的。
一般要尽量注意以下问题:
不要混合使用层和表格排版,如果是父子关系,如层中表格,不在此原则范围内;
内联式的 CSS 在 Netscape Navigator 中经常会出现问题,使用链式或内嵌式;
有时需要在空层插入表格或者透明图片,以保证在 Netscape Navigator 里的效果。对于只有几个像素宽度或高度的层,改用图片来实现;
避免使用 W3C 组织不推荐的排版属性,用 CSS 代替。
4)为何从别的文档拷贝文本到 Dreamweaver ,所有的段落会挤成一团,而在 Dreamweaver 内部又带有格式代码?
Dreamweaver 复制和粘贴文本有二种类别,标准的方式将对象连同对象的属性一起复制,把剪贴板的内容作为 HTML 代码;另一种方式仅复制或粘贴文本,复制时忽视 html 格式,粘帖时则把 html 代码作为文本粘贴。多按一个“ Shift ”( Ctrl+Shift+C/Ctrl+Shift+V )键即按后一种方式操作。
5)为什么网页用 IE 浏览正常,用 Netscape Navigator 却不符合要求甚至出错,而且在 Dreamweaver 的文档窗口老是修改不好?
请检查代码。因为用所见所得编辑器反复修改页面的某些部分,有时会留下一些多余的代码,比如多余的链接,这些代码在 Dreamweaver 的文档窗口看不到, IE 会忽视它们。但是 Netscape Navigator 对代码要求更严格,预览时就出现不可思议的现象。
6)在 Netscape Navigator 中,有些书签( anchor )不起作用,有些好象消失了?
Netscape Navigator 的书签是大小写敏感的。在 Navigator 中,多层嵌套的表格里面的书签会丢失,把书签放到表格外面。
7) Dreamweaver 文档窗口布满了各种各样的面板,为了编辑文档,不得不扒开一个个空隙,太累,如何是好?
一个 800X600 分辩率的屏幕对于 Dreamweaver 来说确实小了些,不过即便是 1024X768 ,也放不下所有的面板。关键是好好组织。
关闭那些在编辑中暂时用不到的面板,把常用的面板放在一起,节省屏幕空间;
除非现在要用,否则关闭“ HTML Source Inspector ”,它除开占用屏幕空间,还占用相当的系统资源;
按 F4 隐藏所有打开的面板,一览文档的全貌,再按一下,显示面板;
在“ Windows ”选单有个“ Arrange Floating Palettes ”命令,使用这个命令将所有打开的面板放在窗口四周,并互不重叠。
多用快捷键并熟练掌握是很好的提高工作效率的方法。
当添加不可见的对象时,Dreamweaver会在文档窗口的页面顶部加上相应的图标,如果图标太多,可能妨碍编辑。可以按“Ctrl+Shift+I ”(主选单 View Invisible Elements )来隐藏和显示它们。也可以设定不出现这些图标,不过不建议这样作,因为它们能帮助选择对象,便于编辑。
8) Head 对象面板只能添加内容,能在文档窗口修改 < head> 标记的内容吗?
可以。有一种非常直观的方式,按“ Ctrl+Shift+W ”(主选单 View Head Content ),在文档窗口主选单栏下出现一行图标,点击这些图标修改。
9)如何选择表格、层里面那些非常小的,比如 1X1px 的图片?
在表格的单元格中点击,然后按下“ Shift ”键,用箭头键移动即可选择。
也可先选定表格单元(按下 Ctrl 键,用鼠标点击相应单元)或者层,然后在“ HTML Source Inspector ”面板中选择高亮代码中的 < img src="..."> ,返回文档窗口,图片即被选择。
10)怎样编辑一个框架系的名字(Title)? 11)如何改变“behaviors”的缺省事件? 将“ onClick="*" ”中的“*”移到“ onMouseOver="" ”中,改为: < A onClick="" onDblClick="" onKeyDown="" onKeyPress="" onKeyUp="" onMouseDown="" onMouseOut="" onMouseOver="*" onMouseUp=""> 12)在打开一个页面时,同时打开一个小窗口,用 Dreamweaver 能够实现吗? 13)插入表格时,在表格单元中老是有个空格( < td> < /td> ),怎样才能不让它产生? 这是 Dreamweaver 自动生成的,不要删除它。如果表格单元里没有任何东西, Netscape Navigator 将不显示该单元。 14)模板文档的 < head> 标记里,除了网页主题外不能编辑,怎样才能将 behaviors 加入到基于该模板的网页? 用“ HTML Source inspector ”面板在模板文档的“ < /head> ”前加入可编辑标记,如下: 15)在合作开发和管理网站时,使用 Dreamweaver 的登记/检查系统,是否为远程服务器的网站的相关文件加上了不同的访问权限? check in/check out 是 Dreamweaver 内部使用的一种管理机制,它与文件的属性无关。“ check out ”意味着该文件正被我使用,别人不能编辑它;“ check in ”则表示该文件可以被别的同事 check out 及编辑,本地的文件就会变成只读,防止自己改变它的内容。 Dreamweaver 通过在本地和远程服务器上产生相应的 “.lck” 文件来实现 check in/check out 功能,这些文件在“ Site ”窗口不显示, Dreamweaver 能够读这些文件,它只对 Dreamweaver 有效。并没有为文件加上什么属性。如果用别的 Ftp 工具和编辑器,仍旧可以打开它们。 16)作网页时,鼠标飞舞,经常改变了设置好的图片的大小。能够不重新查看图片就纠正吗? 如果图片的大小不符,在属性面板,它的值会变成显目的粗体。按面板上的“ Refresh ”按钮,就可恢复成真实大小。 17)如何才能单击一个链接,同时改变多个框架? 最直接的方法就是为该链接建立一个框架系。 用 Dreamweaver 的“ Go to URL ” behavior 更简单。对话框显示所有的框架,在下面的“ URL ”栏填入相应的页面就是。 18)想给文本加上 behavior ,可是 behavior 面板上的项目都是灰暗的,不可选的,怎么办? 上面的作法较繁琐,便捷的方式是将文本链接到“ javascript:void(null) ”,那些 behavior 就老老实实显露出来了。 19)把使用了 behaviors 的层放进 Library 时, Dreamweaver 不让层的 behaviors 跟着走,怎么办? 20)检查 Flash 插件并重定向的脚本有时不正常,还有别的方法吗? 制作 Flash 网页时,人们习惯使用 Dreamweaver 的“ check plugin” behavior 来重定向。但是有时它会错报,明明安装了插件,却说没有。下面介绍一种稳妥的方法来重定向。 制作一个新的首页作为重定向的页面。用“ head ”对象面板的“ Insert Refresh ”定向到未使用 Flash 技术的网页,如图。它会在页面头部加上如下代码: < meta http-equiv="refresh" content="4;URL=noflash.htm"> 另作一个很小的 Flash 影片,在第一帧加上一个“ Get url ”行为,指向使用 Flash 技术的页面。把这个小影片嵌入到用来定向的首页。
按“ Ctrl+F10 ”打开“ Frames ”面板,点击最外面的框,按“ Ctrl+J ”(主选单 Modify Page Properties )。
事件设定文件放在 Dreamweaver 安装目录下的“ ConfigurationBehaviorsEvents ”文件夹,比如对于 4.0 以上版本浏览器,打开文件“ 4.0 and Later Browsers.htm ”。
< A onClick="*" onDblClick="" onKeyDown="" onKeyPress="" onKeyUp="" onMouseDown="" onMouseOut="" onMouseOver="" onMouseUp="">
重新启动 Dreamweaver ,该类缺省事件即变为“onMouseOver ”。其他类推。
能,不用写一行代码。在“ behaviors ”面板使用内置的“ Open Browser Window ”脚本,设定页面、窗口大小、属性。如图:
< !-- #BeginEditable "Javascript" -->
< script language="JavaScript">
< /script>
< !-- #EndEditable -->
以前遇到这种情况,我一般在文本旁边插入一张图片,把需要的 behavior 加在图片上。然后再编辑代码,移到文本上,并去掉图片。
用模板来作。
- 默认分类(20)
- J2EE(25)
- Java(56)
- PHP(55)
- SEO(10)
- 网页设计(20)
- 网站建设(37)
- 数据库(7)
- JavaScript(17)
- JQuery(6)
- MySQL(20)
- SQL Server(6)
- Access(1)
- Oracle(6)
- office(6)
- Dreamweaver(4)
- Photoshop(12)
- Flash(9)
- Fireworks(13)
- CSS(14)
- HTML(4)
- .NET(7)
- ASP(2)
- DB2(1)
- Ajax(2)
- Linux(12)
- Struts(7)
- Hibernate(8)
- Spring(2)
- Jsp(22)
- Asp(8)
- C#(3)
- C++(1)
- 网络安全(5)
- 软件工程(7)
- XML(1)
- English(2)
- 计算机等级考试(2)
- 计算机病毒(4)
- 个人日志(76)
- 互联网(15)
- ActionScript(10)
- Android(3)
- 数据结构与算法(1)
- 游戏策略(3)
- 美文翻译(2)
- 编程开发(19)
- 计算机应用(4)
- 计算机(10)
- Unity3d(6)
- 其他(1)
- egret(1)