CGI

Everything else that doesn't fall into one of the other PB categories.
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

CGI

Post 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?
Paul Dwyer
Network Engineer
Aussie in Tokyo
freak
PureBasic Team
PureBasic Team
Posts: 5947
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Post 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:
Paul Dwyer
Network Engineer
Aussie in Tokyo
freak
PureBasic Team
PureBasic Team
Posts: 5947
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Post by Paul Dwyer »

Thanks!

I wonder if there an API call for getting an environment Var?
Paul Dwyer
Network Engineer
Aussie in Tokyo
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Post by Paul Dwyer »

Sorry, another question.

Would the lib work with Linux too or would I need to find a separate linux lib?
Paul Dwyer
Network Engineer
Aussie in Tokyo
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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).
Paul Dwyer
User
User
Posts: 44
Joined: Wed Nov 05, 2003 4:34 am
Location: Tokyo, Japan

Solved!

Post by Paul Dwyer »

You're a legend!

8)
Paul Dwyer
Network Engineer
Aussie in Tokyo
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Post 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.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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,
El_Choni
Post Reply