คลังเก็บหมวดหมู่: Programming

Get Real IP Address with ASP

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")
ข้อความนี้ถูกเขียนใน Programming และติดป้ายกำกับ บน โดย

function makeurl($param)

function makeurl($param)
{
$replace=str_replace(' ','-',$param);
$replace=str_replace('&','and',$replace);
$replace=str_replace('/','-',$replace);
$replace=str_replace('(','',$replace);
$replace=str_replace(')','',$replace);
$replace=str_replace('+','',$replace);
$replace=str_replace('#','',$replace);
$replace=str_replace("'",'-',$replace);
$replace=str_replace('"','-',$replace);
return $replace;
}

จะเป็น function ในการ เปลี่ยน – ‘ / ( ) # ‘ ” ให้เป็น – เพื่อให้เหมาะสมกับการค้นหาของ google

ข้อความนี้ถูกเขียนใน Programming และติดป้ายกำกับ บน โดย

Function Ceiling หรือ Floor สำหรับ ASP

เนื่องจาก ASP Classic ไม่มี function Ceiling หรือ Floor สำหรับ การปัดเศษขึ้นลง ซึ่งถือว่ามีความจำเป็นมาก เลยเก็บมาไว้ให้ดูกันครับ

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
ข้อความนี้ถูกเขียนใน Programming และติดป้ายกำกับ บน โดย