1. cgi question

hello all

In a linux server in the web, I call a Euphoria program, called euCode and sending a variable called "name" and its value. For example, to do this, I open a web Brouser with this address and parameters:

www.servidor.com.br/euCode?name=Euphoria

Does anyone know how to capture the value of this variable within the code "euCode.ex" as is done in PHP?

Thanks in advance

Sergio

new topic     » topic index » view message » categorize

2. Re: cgi question

sergelli said...

hello all

In a linux server in the web, I call a Euphoria program, called euCode and sending a variable called "name" and its value. For example, to do this, I open a web Brouser with this address and parameters:

www.servidor.com.br/euCode?name=Euphoria

Does anyone know how to capture the value of this variable within the code "euCode.ex" as is done in PHP?

I believe that they are passed in as environment variables. So, you should try:

object name = getenv("name") 

Note that I used an object, because if it doesn't exist, you'll get an atom back from getenv().

You might also take a look at the submitted CGI libraries at rapideuphoria.com.

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: cgi question

mattlewis said...
sergelli said...

hello all

In a linux server in the web, I call a Euphoria program, called euCode and sending a variable called "name" and its value. For example, to do this, I open a web Brouser with this address and parameters:

www.servidor.com.br/euCode?name=Euphoria

Does anyone know how to capture the value of this variable within the code "euCode.ex" as is done in PHP?

I believe that they are passed in as environment variables. So, you should try:

object name = getenv("name") 

Note that I used an object, because if it doesn't exist, you'll get an atom back from getenv().

Close! It's passed via the QUERY_STRING environment variable. Then you have to parse it from there. Here is a quick example I whipped up using a hash table (map) to store the key/value pairs.

include "std/get.e" 
include "std/map.e" as map 
include "std/pretty.e" 
include "std/search.e" 
include "std/sequence.e" as seq 
include "std/text.e" 
include "std/types.e" 
 
-- get the query string environment variable 
constant QUERY_STRING = getenv("QUERY_STRING") 
 
function url_decode( sequence str ) 
     
    integer posn = find( '%', str ) 
     
    while posn do 
         
        object code = value( '#' & str[posn+1..posn+2] ) 
         
        if code[1] = GET_SUCCESS then 
            str = replace( str, code[2], posn, posn+2 ) 
        end if 
         
        posn = find( '%', str, posn ) 
    end while 
     
    str = find_replace( '+', str, ' ' ) 
     
    return str 
end function 
 
public function query_string() 
     
    -- this is where we will hold the query variables 
    map v_GET = map:new() 
     
    -- was the environment variable set? 
    if sequence( QUERY_STRING ) then 
         
        -- trim any wrapping quotes from the string 
        sequence query = trim( QUERY_STRING, '"' ) 
         
        -- split the query string on ampersand or semicolon 
        -- (semicolon is rarely used but part of the standard) 
        sequence parts = seq:split_any( query, "&;" ) 
         
        -- loop through all the parts 
        for i = 1 to length( parts ) do 
             
            -- split this part into its key/value pair 
            sequence subparts = seq:split( parts[i], '=', 0, 2 ) 
             
            -- decode the encoded parts 
            subparts[1] = url_decode( subparts[1] ) 
            subparts[2] = url_decode( subparts[2] ) 
             
            -- does this key already have a value? 
            if map:has( v_GET, subparts[1] ) then 
                 
                -- get the old value 
                sequence temp = map:get( v_GET, subparts[1] ) 
                 
                -- if the old value was a single string 
                -- make it a sequence so we can append, 
                if string( temp ) then 
                    temp = {temp} 
                end if 
                 
                -- append the new value to the sequence 
                subparts[2] = append( temp, subparts[2] ) 
                 
            end if 
             
            -- add or replace the key's value 
            map:put( v_GET, subparts[1], subparts[2] ) 
             
        end for 
         
    end if 
     
    return v_GET 
end function 

Be sure to check out other useful environment variables:

Hope that helps! smile

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: cgi question

Thank you, your method works, but I found a much easier way.

Instead of calling:

www.myServer.com/myPgm.html&params=XXXXX

I do the following:

www.myServer.com/myPgm&XXXXX

Note that myPgm is a compiled code and capture the value XXXXX, by this way:

 myValue = COMMAND_LINE()   -- capture 
myValue = myValue [3]      -- now, myValue is "XXXXX" 

Sounds simple and useful?

Happy Holidays to all

new topic     » goto parent     » topic index » view message » categorize

5. Re: cgi question

sergelli said...

Sounds simple and useful?

Happy Holidays to all

It doesn't really seem "correct" to me. getlost

-Greg

new topic     » goto parent     » topic index » view message » categorize

6. Re: cgi question

ghaberek said...
sergelli said...

Sounds simple and useful?

Happy Holidays to all

It doesn't really seem "correct" to me. getlost

-Greg

I agree. This does seem to be in violation of section 4.4 of RFC 3875: http://www.ietf.org/rfc/rfc3875

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu