Artikel ini terutama memperkenalkan metode membatasi akses IP ke implementasi ASP tunggal.
Membatasi IP untuk mengakses hanya sekali, sekarang saya akan membagikan kode ASP dengan Anda:
- <%
- '///////////////////////////////////////////////// THR//////////////////////////////
- '////
- '// Fungsi: Satu alamat IP hanya memungkinkan akses ke halaman ini sekali //
- '// kutipan: <!-#includeFile = check_ip.asp-> //
- '////
- '///////////////////////////////////////////////// THR//////////////////////////////
- 'Response.charset = 936' Atur output encoding ke Cina yang disederhanakan
- 'Response.buffer = false' tutup buffer
- DIMFSO, TS, IPLIST, CFS
- 'Atur fungsi cookie
- FunctionsetCookie ()
- Response.cookies (isBrow) = alis
- Response.cookies (isBrow) .Expires = Tanggal+365
- Fungsi endfungsi
- 'Catat fungsi alamat IP
- FunctionWriteIP (nama file, ipaddress)
- SetFSO = server.CreateObject (scripting.filesystemObject)
- Setts = fso.opentextFile (server.mappath (fileName), 8, true)
- ts.writeLineipaddress
- ts.close
- Setts = tidak ada
- Setfso = tidak ada
- Fungsi endfungsi
- 'Baca fungsi alamat IP
- Functionreeadiplist (nama file)
- SetFSO = server.CreateObject (scripting.filesystemObject)
- Ifnotfso.fileexists (server.mappath (fileName)) lalu
- CreateFile (iPlist.txt)
- Fungsi keluar
- Endif
- Setts = fso.opentextFile (server.mappath (fileName))
- Iplist = ts.readall
- ts.close
- Setts = tidak ada
- Setfso = tidak ada
- REATIPLIST = IPLIST
- Fungsi endfungsi
- 'Buat fungsi file
- FunctionCreateFile (nama file)
- SetFSO = server.CreateObject (scripting.filesystemObject)
- Setcfs = fso.createTextFile (server.mappath (fileName))
- Cfs.close
- Setcfs = tidak ada
- Setfso = tidak ada
- Fungsi endfungsi
- 'Tutup fungsi jendela IE saat ini (CATATAN: Lulus di bawah IE6, browser lain belum mengujinya)
- Functionclosewindow ()
- 'Response.write <script> window.location =' javaScript: window.opener = null; window.close (); '</script>
- Response.redirectthttp: //www.baidu.com
- Fungsi endfungsi
- Ip = request.serverVariable (remote_addr) 'Dapatkan alamat IP pemirsa
- Cookie = request.cookies (isBrow) 'Dapatkan cookie saat ini
- 'Response.WriteCookie
- Ifrequest.serverVariable (http_x_forwarded_for) <> lalu
- Response.write Situs ini tidak mengizinkan akses proxy
- Response.end ()
- Kalau tidak
- Ifcookie = browthen
- CloseWindow ()
- Kalau tidak
- Ifinstr (readiplist (iPlist.txt), IP) <> 0then
- CloseWindow ()
- Kalau tidak
- WritePiplist.txt, ip
- Endif
- SetCookie ()
- Endif
- Endif
- %>
Di atas adalah kode implementasi ASP yang dibagikan kepada Anda, saya harap ini akan membantu pembelajaran Anda.