Page 1 of 1

CGI

Posted: Thu Nov 06, 2003 2:43 am
by Paul Dwyer
I was just wondering how I can get post and get variables from a website when writing a CGI app.

Generally you look in environment variables for the data but I can't see how purebasic reads Environment variables...

anyone have a real simple CGI example?

Posted: Thu Nov 06, 2003 3:17 am
by freak
There is a usermade library avaiable to use CGI.

http://www.reelmediaproductions.com/pb/

Just type 'CGI' in the search box at the top, and you'll find it.

Timo

Posted: Thu Nov 06, 2003 3:25 am
by Paul Dwyer
Thanks, I'll take a look

Is a whole lib really needed? Other languages have a GetEnv or Environ$() call to get the data, after that it's all your own working code and print statemements isn't it?

Does PB not have a way to get an environment var? :roll:

Posted: Thu Nov 06, 2003 3:37 am
by freak
> Other languages have a GetEnv or Environ$() call to get the data,

The lib doesn't do much more than that. There are functions to
decode/encode Urls, and one to send the Output back, that's all.

and, no PB doesn't have a way for that, why else should there be a lib for it? :wink:

Timo

Posted: Thu Nov 06, 2003 3:42 am
by Paul Dwyer
Thanks!

I wonder if there an API call for getting an environment Var?

Posted: Thu Nov 06, 2003 3:45 am
by Paul Dwyer
Sorry, another question.

Would the lib work with Linux too or would I need to find a separate linux lib?

Posted: Thu Nov 06, 2003 5:56 am
by PB
> Is a whole lib really needed?

PureBasic will (usually) just include the command data from a lib into
your final exe (if the lib is coded that way). So no, using one command
from a library doesn't always include the whole library code in your exe.

> Does PB not have a way to get an environment var?

Not as a native command, but you can do it with the API:
viewtopic.php?t=7019

Remember: if PureBasic lacks a command, you can almost always use
an API command (or two) to do the job instead. ;) (Although this is
only for Windows).

Solved!

Posted: Thu Nov 06, 2003 6:15 am
by Paul Dwyer
You're a legend!

8)

Posted: Fri Nov 07, 2003 1:05 am
by Doobrey
Paul Dwyer wrote: Would the lib work with Linux too ?
Nope, well...maybe (I dunno if the lib format differs from Win and Linux versions)
Anyway, it`s a definate no if the lib uses any OS API calls or calls to 3rd party shared librarys.

Posted: Fri Nov 07, 2003 5:14 am
by El_Choni
Hi,

This is, more or less, what the StdIn command of the CGI lib does, translated to PB+Win32API:

Code: Select all

bRead.l
hInput = GetStdHandle_(#STD_INPUT_HANDLE)
GetSystemInfo_(sinf.SYSTEM_INFO)
SetConsoleMode_(hInput, #ENABLE_LINE_INPUT|#ENABLE_ECHO_INPUT|#ENABLE_PROCESSED_INPUT)
Buffer = AllocateMemory(0, sinf\dwPageSize)
While ReadFile_(hInput, Buffer, sinf\dwPageSize-1, @bRead, 0) And bRead
  Text$+PeekS(Buffer)
Wend
FreeMemory(0)
Debug Text$ ; there it is
This code is useless if ran as is, in console mode, but it's helpful if you use it as CGI input.

I think it should be easy to do this in Linux (should be easier, so they say ;)

Regards,