[Gambas-devel] Release of gambas 1.9.5

Rob sourceforge-raindog2 at ...19...
Thu Apr 7 17:29:29 CEST 2005


On Thursday 07 April 2005 07:03, fabien wrote:
> if you have an idea to emulate the session process

You can implement sessions by setting a cookie and using the value of 
that cookie as the primary key in a database table where you store 
whatever session data you need to.  I don't think I ever experimented 
with cookies in Gambas CGI though.

> And i don't remember how to use GET and POST, can you refresh my
> memory ?

With GET, the form data is in Application.Env["QUERY_STRING"].  With 
POST, you need to LINE INPUT (from stdin) into a variable to get the 
data.  Either way, then you need to decode it.  I have not tested the 
following code except for hexpairdecode() which is from my original 
CGI example which only handled GET, but it's what I would try first:

Public Sub ProcessForm()

        dim rawdata as String
        dim pairs as String[]
        dim formdata as new Collection
        dim pair as string
        dim pairvals as new String[]

        rawdata = Application.Env["QUERY_STRING"] ' retrieve GET 
variables
        if rawdata <> "" then rawdata = rawdata & "&"
        LINE INPUT rawdata ' retrieve POST variables
        pairs = Split(rawdata, "&")
        for each pair in pairs
                pairvals.Clear
                pairvals = Split(pair, "=")
                formdata[pairvals[0]] = urldecode(pairvals[1])
        next

        ' do something with the variables....

end

function urldecode(inval as string) as string

	dim outval as string
        dim i as integer

        for i = 1 to len(inval)
        	if mid(inval,i,1) = "%" and i < (len(inval) - 2) then
                	outval = outval & hexpairdecode(mid(inval, i+1, 2))
                        i = i + 2
                elseif mid(inval, i, 1) = "+" then
                	outval = outval & " "
                else
                	outval = outval & mid(inval,i,1)
                endif
	next

end

STATIC PUBLIC FUNCTION hexpairdecode(invar AS String) AS String

  ' deal with invalids
  IF Len(invar) <> 2 THEN RETURN " "
  IF Instr("0123456789abcdef", LCase(Left(invar,1))) < 1 THEN RETURN " 
"
  IF Instr("0123456789abcdef", LCase(Right(invar,1))) < 1 THEN RETURN 
" "

  ' quick'n'dirty hex pair decoder
  RETURN Chr$(Instr("123456789abcdef", LCase(Left(invar,1))) * 16 + 
Instr("123456789abcdef", LCase(Right(invar,1))))

END

' Rob






More information about the Devel mailing list