【ASP】產生GUID
GUID全名是Globally Unique Identifier,依據微軟的說法:GUID 是一個 128 位元的整數 (16 位元組),可以在需要唯一識別項時用於所有電腦和網路。
因為重複的機率很低,可以用來當做資料庫的key值,以避免以流水號當作key值時,可以修改網址參數而偷看到別人的資料。
程式:
Function GetGuid()
Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
tg = TypeLib.Guid
GetGuid = mid(tg, 2 ,len(tg)-4)
Set TypeLib = Nothing
End Function
response.write GetGuid() & "<br/>"
response.write GetGuid()
執行結果:
64D1C0F6-DD7E-4CAA-B6A6-D8053549B14D
6F24F46A-E1C7-42B8-8CF1-E2663F28DC7B
PS:結果值是個參考,每次執行都不同
留言
張貼留言