How to ? : CGI, Websites and native Purebasic use

Just starting out? Need help? Post your questions and find answers here.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

How to ? : CGI, Websites and native Purebasic use

Post by Rings »

as i need some cgi support (and don't want use a userlib) ,
i prefer using PB's native Input/writestring commands.
(crossplattform perhaps)
are there any examples out there how to write a simple
cgi.exe with a simple html example ?
cannot found any in the example-folder........


That is what i have today:

Purebasic (Api) Code:

Code: Select all

hInput = GetStdHandle_(#STD_INPUT_HANDLE)

SetConsoleMode_(hInput, #ENABLE_LINE_INPUT|#ENABLE_ECHO_INPUT|#ENABLE_PROCESSED_INPUT)

*ContentLength = AllocateMemory(128)

ContentLength = Val(PeekS(*ContentLength, GetEnvironmentVariable_("CONTENT_LENGTH", *ContentLength, 128)))

FreeMemory(*ContentLength)

*Buffer = AllocateMemory(ContentLength)

ReadFile_(hInput, *Buffer, ContentLength, @bRead, 0)

Input$ = PeekS(*Buffer)

FreeMemory(*Buffer)

CloseHandle_(hInput)

hOutput = GetStdHandle_(#STD_OUTPUT_HANDLE)

HttpAnswer$ = "Content-type: text/html"+Chr(10)+Chr(13)+Chr(10)+Chr(13)+"<html><header><title>Answer from CGI</title></header><body>Hi, received your data:<br>"

HttpAnswer$+StringField(StringField(Input$, 1, "&"), 1, "=")+": "+StringField(StringField(Input$, 1, "&"), 2, "=")+"<br>"+StringField(StringField(Input$, 2, "&"), 1, "=")+": "+StringField(StringField(Input$, 2, "&"), 2, "=")

HttpAnswer$+"</body></html>"

WriteFile_(hOutput, @HttpAnswer$, Len(HttpAnswer$), @Written, 0)

CloseHandle_(hOutput)
put the compiled console exe in cgibin folder.


and the html for the XAMP (apache) server:

Code: Select all

<H3>MultiImage Request Form cgitest</H3>
<P>
<FORM ACTION="../cgi-bin/CGIMIMAGE.exe" METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE=FILE NAME="P1_imagefile" SIZE=35 MAXLENGTH=50><BR>
</P>
<P>
<INPUT TYPE="submit" VALUE="Send the pictures">
</P>
</FORM>

any help ?
SPAMINATOR NR.1
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

You should try Paul's CGI lib!
I also tried to use PB native to make cgi's and it got weird.

Paul's lib supports all the most important things you can think on cgi programming also including multiple files uploads.

I have created cgi's exe with paul's lib and got great results.

You can judge for yourself here: http://www.cellphoto.net

the whole site is working under cgi's made with purebasic :)
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I don't see a problem really.
There is the GetEnvironmentVariable() command to access all the CGI variables,
like CONTENT_LENGTH, QUERY_STRING etc.

To read in the POST data, you can either use Input() to get it in string format,
or ReadConsoleData() to read it into a buffer.
To write back to the server, use Print(), PrintN() or WriteConsoleData()

It is all there since PB4. The linux version has all of it as well (allready wrote some CGI's with the linux version),
and the mac version will get it too of course.

Of course that is just the basic stuff... You still need to do stuff like
encoding/decoding urls yourself. If you want that done too, you'll need a userlib.
quidquid Latine dictum sit altum videtur
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

first, thx for your replies.
Pantcho:I dont't wanna use a userlib without source,
most ppl here know why.
And second, i don't wanna use native Api
(if i want, i can use that code i post in front, it works :)

I want use native 'Purebasic' for that.

And next,

Freak: Yes, i know its possible, that is why i ask here
for an example.
Purebasic could be the ideal tool for building
CGI's. Except that there are no example provided
from the offical Pure-team, or anyone else.
SPAMINATOR NR.1
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post by CadeX »

Pantcho!! wrote:You should try Paul's CGI lib!
I also tried to use PB native to make cgi's and it got weird.

Paul's lib supports all the most important things you can think on cgi programming also including multiple files uploads.

I have created cgi's exe with paul's lib and got great results.

You can judge for yourself here: http://www.cellphoto.net

the whole site is working under cgi's made with purebasic :)
Is there even a PB 4.* version out yet?
Pro-Gamer, Programmer, Pro-Grammer
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

SPAMINATOR NR.1
Post Reply