ASP (Active Server Page) Classic
Posted by (0) Comment
เนื่องจากอย่างว่าตอนนี้ต้องเขียน SQL Script เยอะกว่าสมัยก่อนตอนหัดเขียนโปรแกรมใหม่ๆ แล้ว Code SQL มันก้อยาวมาก หลังจากนั้นไม่พอ ยังต้องเอามาแปะใน ASP อีกต่างหาก ปัญหาก็คือ มันไม่ใช่ว่าจะวางแล้ว Assign ค่าใส่ตัวแปลที่เป็น String ได้เลยเสียเมื่อไหร่ เพราะถ้า copy ล่ะก็มันก็จะขึ้นบรรทัดใหม่ มันก่อให้เกิด Error ขึ้นมา เลยต้องมาต่อตัวแปล String ทีละบรรทัด แล้วถ้าเขียน SQL Script เป็น 50 บรรทัดไม่หน้ามืดเลยเหรอ
นั่นแหละครับ ประเด็น ผมเลยเขียนโปรแกรมง๊ายง่าย ขึ้นมาอันนึง เพื่อทำขั้นตอนนี้ให้เราแทน (มันง่ายๆจริงๆ นะ แต่ถ้ามีหลายบรรทัดแล้วจะยิ้มเลยล่ะ) ลองโหลดไปใช้งานกันดูนะครับ
ใครลองโหลดไปเล่น เสนอไอเดียทำต่อได้เลยนะครับ
Error: Request object error ‘ASP 0104 : 80004005′ Operation not Allowed
Error นี้ เกิดจาก การอัพโหลดไฟล์เกิน 200Kb ซึ่งเกิดจากการ Config ใน Metabase.xml ซึ่ง ถ้าจะแก้ไขให้ไปหาไหล์ Metabase.xml ใน folder C:\Windows\System32\Inetsrv ซึ่ง หา บรรทัดนี้
AspMaxRequestEntityAllowed
แล้วเพิ่มตัวเลขข้างหลังตามต้องการ
การเขียน QueryString อัตโนมัติ ด้วย ASP
คงมีบางคนอยากสร้าง QueryString แบบอัตโนมัิติบ้าง เพราะไม่เช่นนั้นต้องมาดูตัวแปลตั้งหมดแล้วเขียนเขียนมาเองทั้งหมดผมว่ามันลำบากเกินไป อันนี้เป็น Function ที่สำหรับสร้าง QueryString แบบ อัตโนมัติ โดยส่งเพียงค่า Parameter สำหรับชื่อตัวแปลที่ไม่ต้องการให้ทำการสร้าง QueryString ใน Function (กรณีเช่น การส่งหน้า ซึ่งจะส่งค่าเปลี่ยนไปทุกๆ หน้าไม่ Fix ตายตัว)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function makeQueryString(var_dynparam) if request.ServerVariables("REQUEST_METHOD") = "POST" then for each variable_name in request.form variablevalue=request.form(variable_name) if variable_name <> var_dynparam then a = a&"&"&variable_name &"="&variable_value end if next else for each variable_name in request.querystring variablevalue=request.querystring(variable_name) if variable_name <> var_dynparam then a = a&"&"&variable_name &"="&variable_value end if next end if makeQueryString = a end function |
วิธีเรียกใช้
Posted by (0) Comment
Whenever a browser sends a request for a page, it also sends a number of other headers to the script, containing information such as the browser type. It also includes information such as the visitors IP address. This can be particularly useful when creating an online security scan, or logging their IP address in an online forum.
There are two server variables of interest; REMOTE_ADDR and HTTP_X_FORWARDED_FOR. As many visitors access the internet via a third party (ie their ISP), REMOTE_ADDR does not always contain their IP address… it contains their ISP’s address. If this is the case, most browsers then store the users IP address in the HTTP_X_FORWARDED_FOR variable. So, first, we check HTTP_X_FORWARDED_FOR, and then if that is empty, we try REMOTE_ADDR instead:
Dim sIPAddress sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If sIPAddress="" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")
เนื่องจาก ASP Classic ไม่มี function Ceiling หรือ Floor สำหรับ การปัดเศษขึ้นลง ซึ่งถือว่ามีความจำเป็นมาก เลยเก็บมาไว้ให้ดูกันครับ
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 | Function Ceiling(byval n) Dim iTmp, bErr, f on error resume next n = cdbl(n) if err then bErr = true on error goto 0 if bErr then Err.Raise 5000, "Ceiling Function", _ "Input must be convertible to a sub-type of double" f = Floor(n) if f = n then Ceiling = n Exit Function End If Ceiling = cInt(f + 1) End Function Function Floor(byval n) Dim iTmp, bErr on error resume next n = cdbl(n) if err then bErr = true on error goto 0 if bErr then Err.Raise 5000, "Floor Function", _ "Input must be convertible to a sub-type of double" 'Round() rounds up iTmp = Round(n) 'test rounded value against the non rounded value 'if greater, subtract 1 if iTmp > n then iTmp = iTmp - 1 Floor = cInt(iTmp) End Function |