CGI Using in Native Purebasic

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

CGI Using in Native Purebasic

Post by Rings »

Hi guys, after no receive from the lazy Purebasic-forum here, i wrote
my own samples for using cgi with purebasic and Apache (mostly used webserver) from the xamp-package.
Thx freak for the hint with the GetEnvironment...() .
(see http://www.purebasic.fr/english/viewtopic.php?t=25030 )

Compile the Purecode to a Console-Exe named 'CGIMIMAGE.exe"
and put it in the cgi-bin folder of xamp .
The html-example put in the doc's folder of xamp (normaly 'htdocs')
Start your brwoser and navigate to 127.0.0.1 .......

Fee free to use this code in your app !
Its Pure Source, no Lib no version problems !

@Andre: you can include this in the purearea-snippets

This is a simple html-page:

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>

<FORM name="textsending_easy" ACTION="../cgi-bin/CGIMIMAGE.exe" ENCTYPE="text/plain" METHOD="POST">
<INPUT TYPE=Text Name="P2_MyText" Value="Type some stuff to send here" SIZE=35 MAXLENGTH=50></P>
<P>
<INPUT TYPE="submit" VALUE="Send the Text">
</P>
</FORM>


<form name="Layoutbereich1FORM" action="../cgi-bin/CGIMIMAGE.exe"" enctype="text/plain" method="post">
using Purebasic<input id="Formularmarkierungsfeld1" name="Purebasic" value="yes" type="checkbox"><br>
using VB<input id="Formularmarkierungsfeld2" name="Visual Basic" value="holla" type="checkbox"><br>
using DotNet<input id="Formularmarkierungsfeld3" name="VB.NET" value="uups" type="checkbox"><br>
Use other stuff<input id="Formularmarkierungsfeld4" name="Other" value="ok" type="checkbox"><br>
your name<input id="Formulareditierfeld5" name="NickName" value="RINGS" size="40" maxlength="40" type="text"><br>
your email<input id="Formulareditierfeld6" name="email-addi" value="karl@nospam.fr" size="43" maxlength="43" type="text"><br>
<input name="FormularHandler1" value="Sending" id="FormularHandler1" type="submit"></td>
</form>

Code: Select all

;CGI-Example for Web-server using
; native Purebasic, tested with apache
; (C) 2006 by Siegfried Rings
; free for use, 
; but forbidden to making shitty non-source librarys from !
; and also forbidden to make shitty source-collections from (Except my permission)
; and also PLZ do Not Remove this shitty Header ;) !!!!

;Compile as Console-Exe

;ToDo: A Lot, the filsize is not exactly
;      Test with other servers


OutputContentType.s="Content-type: text/html"
OutputContentType.s="Content-type: text/html;charset=UTF-8"
AnswerTitle.s="Answer from PureBasic-CGI"

Folder.s=""; "C:\"
DebugInput=0   

Global CGI_AUTH_TYPE.s
Global CGI_CONTENT_LENGTH.s
Global CGI_CONTENT_TYPE.s
Global CGI_DOCUMENT_ROOT.s
Global CGI_GATEWAY_INTERFACE.s
Global CGI_PATH_INFO.s
Global CGI_PATH_TRANSLATED.s
Global CGI_QUERY_STRING.s
Global CGI_REMOTE_ADDR.s
Global CGI_REMOTE_HOST.s
Global CGI_REMOTE_IDENT.s
Global CGI_REMOTE_PORT.s
Global CGI_REMOTE_USER.s
Global CGI_REQUEST_URI.s
Global CGI_REQUEST_METHOD.s
Global CGI_SCRIPT_NAME.s
Global CGI_SCRIPT_FILENAME.s
Global CGI_SERVER_ADMIN.s
Global CGI_SERVER_NAME.s
Global CGI_SERVER_PORT.s
Global CGI_SERVER_PROTOCOL.s
Global CGI_SERVER_SIGNATURE.s
Global CGI_SERVER_SOFTWARE.s 
Global CGI_HTTP_ACCEPT.s
Global CGI_HTTP_ACCEPT_ENCODING.s
Global CGI_HTTP_ACCEPT_LANGUAGE.s
Global CGI_HTTP_COOKIE.s
Global CGI_HTTP_FORWARDED.s
Global CGI_HTTP_HOST.s
Global CGI_HTTP_PRAGMA.s
Global CGI_HTTP_REFERER.s
Global CGI_HTTP_USER_AGENT.s

Procedure Get_CGI_Var()
;     * AUTH_TYPE - Describes the authentication method used by the web browser If any authentication method was used. This is Not set unless the script is Protected.
CGI_AUTH_TYPE  = GetEnvironmentVariable("AUTH_TYPE")    


;     * CONTENT_LENGTH - This is used For scripts that are receiving form Data using the POST method. This variable tells the byte length of the CGI input Data stream. This is required To Read the Data from the standard input With the POST method.
CGI_CONTENT_LENGTH  = GetEnvironmentVariable("CONTENT_LENGTH")    


;     * CONTENT_TYPE - Tells the media type of Data being received from the user. this is used For scripts called using the POST method.
CGI_CONTENT_TYPE  = GetEnvironmentVariable("CONTENT_TYPE")    


;     * DOCUMENT_ROOT - The root path To the home HTML page For the server. Example:
;       /home/httpd/html
CGI_DOCUMENT_ROOT  = GetEnvironmentVariable("DOCUMENT_ROOT")    


;     * GATEWAY_INTERFACE - The version of the common gateway Interface (CGI) specification being used To exchange the Data between the client And server. this is normally CGI/1.1 For the current revision level of 1.1. 
;   Example:   CGI/1.1
CGI_GATEWAY_INTERFACE  = GetEnvironmentVariable("GATEWAY_INTERFACE")    


;     * PATH_INFO - Extra path information added To the End of the URL that accessed the server side script program.
CGI_PATH_INFO  = GetEnvironmentVariable("PATH_INFO")    


;     * PATH_TRANSLATED - A translated version of the PATH_INFO variable translated by the webserver from virtual To physical path information.
CGI_PATH_TRANSLATED  = GetEnvironmentVariable("PATH_TRANSLATED")    


;     * QUERY_STRING - This string contains any information at the End of the server side script path that followed a question mark. Used To Return Data If the GET method was used by a form. There are length restrictions To the QUERY_STRING. Example of how To set it in HTML:
;       <A HREF="/cgi-bin/hits.pl?mainpage></A>
;       The information after the ? is the QUERY_STRING which is "mainpage" in this Case. How it looks on the server side
;       mainpage
CGI_QUERY_STRING  = GetEnvironmentVariable("QUERY_STRING")    


;     * REMOTE_ADDR - The IP address of the client computer. Example:
;       132.15.28.124
CGI_REMOTE_ADDR  = GetEnvironmentVariable("REMOTE_ADDR")    


;     * REMOTE_HOST - The fully qualified domain name of the client machine making the HTTP request. It may Not be possible To determine this name since many client computers names are Not recorded in the DNS system. Example:
;       comp11.mycompanyproxy.com
CGI_REMOTE_HOST  = GetEnvironmentVariable("REMOTE_HOST")    


;     * REMOTE_IDENT - The ability To use this variable is limited To servers that support RFC 931. This variable may contain the client machine's username, but it is intended to be used for logging purposes only, when it is available.
CGI_REMOTE_IDENT  = GetEnvironmentVariable("REMOTE_IDENT")    


;     * REMOTE_PORT - The clients requesting port. An example:
;       3465
CGI_REMOTE_PORT  = GetEnvironmentVariable("REMOTE_PORT")    


;     * REMOTE_USER - If the CGI script was Protected And the user had To be logged in To get access To the script, this value will contain the user's log in name
CGI_REMOTE_USER  = GetEnvironmentVariable("REMOTE_USER")    


;     * REQUEST_URI - The path To the requested file by the client. An example:
;       /cgi-bin/join.pl?button=on
CGI_REQUEST_URI  = GetEnvironmentVariable("REQUEST_URI")    


;     * REQUEST_METHOD - This describes the request method used by the browser which is normally GET, POST, Or HEAD.
CGI_REQUEST_METHOD  = GetEnvironmentVariable("REQUEST_METHOD")    


;     * SCRIPT_NAME - The virtual path of the CGI script being executed. Example:
;       /cgi-bin/join.pl
CGI_SCRIPT_NAME  = GetEnvironmentVariable("SCRIPT_NAME")    


;     * SCRIPT_FILENAME - Example:
;       /home/httpd/cgi-bin/join.pl
CGI_SCRIPT_FILENAME  = GetEnvironmentVariable("SCRIPT_FILENAME")    

;     * SERVER_ADMIN - The e-mail address of the server administrator. Example:
;       webadmin@myhost.mycompany.org
CGI_SERVER_ADMIN  = GetEnvironmentVariable("SERVER_ADMIN")    


;     * SERVER_NAME - The server hostname, IP address Or DNS alias name shown As a self referencing URL. This does Not include the protocol identifier such As "HTTP:", the machine name, Or port number. Example:
;       myhost
CGI_SERVER_NAME  = GetEnvironmentVariable("SERVER_NAME")    


;     * SERVER_PORT - The port number the HTTP requests And responses are being sent on. Example:
;       80
CGI_SERVER_PORT  = GetEnvironmentVariable("SERVER_PORT")    


;     * SERVER_PROTOCOL - This value is normally HTTP which describes the protocol being used between the client And server computers. Example:
;       HTTP/1.1
CGI_SERVER_PROTOCOL  = GetEnvironmentVariable("SERVER_PROTOCOL")    


;     * SERVER_SIGNATURE - Server information specifying the name And version of the web server And the port being serviced. Example:
;       Apache/1.3.12 Server at mdct-dev3 Port 80
CGI_SERVER_SIGNATURE  = GetEnvironmentVariable("SERVER_SIGNATURE")    


;     * SERVER_SOFTWARE - The name And version of the web server. Example:
;       Apache/1.3.12 (Unix) (Red Hat/Linux) PHP/3.0.15 mod_perl/1.21
CGI_SERVER_SOFTWARE  = GetEnvironmentVariable("SERVER_SOFTWARE")     


;     * HTTP_ACCEPT - The media types of Data that the client browser can accept. these Data types are separated by commas. An example:
;       image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*
CGI_HTTP_ACCEPT  = GetEnvironmentVariable("HTTP_ACCEPT")    


;     * HTTP_ACCEPT_ENCODING An example:
;       gzip, deflate
CGI_HTTP_ACCEPT_ENCODING  = GetEnvironmentVariable("HTTP_ACCEPT_ENCODING")    


;     * HTTP_ACCEPT_LANGUAGE - The language the client browser accepts. Example:
;       en-us
CGI_HTTP_ACCEPT_LANGUAGE  = GetEnvironmentVariable("HTTP_ACCEPT_LANGUAGE")    


;     * HTTP_COOKIE - Used As an environment variable that contains cookies associated With the server domain from the browser.
CGI_HTTP_COOKIE  = GetEnvironmentVariable("HTTP_COOKIE")    


;     * HTTP_FORWARDED An example:
;       by http://proxy-nt1.yourcompany.org:8080 (Netscape-Proxy/3.5)
CGI_HTTP_FORWARDED  = GetEnvironmentVariable("HTTP_FORWARDED")    


;     * HTTP_HOST An example:
;       yourwebhost.yourcompany.org
CGI_HTTP_HOST  = GetEnvironmentVariable("HTTP_HOST")    


;     * HTTP_PRAGMA - An example:
;       No-Cache
CGI_HTTP_PRAGMA  = GetEnvironmentVariable("HTTP_PRAGMA")    


;     * HTTP_REFERER - The page address where the HTTP request originated. An example:
;       http://ctdp.tripod.com/independent/web/cgi/cgimanual/index.html
CGI_HTTP_REFERER  = GetEnvironmentVariable("HTTP_REFERER")    


;     * HTTP_USER_AGENT - The name of the client web browser being used To make the request. Example:
;       Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)
CGI_HTTP_USER_AGENT  = GetEnvironmentVariable("HTTP_USER_AGENT") 

EndProcedure

OpenConsole() ;Needed For Output
EnableGraphicalConsole(0) ;set for redirecting

;Letz do some basic CGI-Stuff, get all those environment variables
Get_CGI_Var()

ContentLength = Val(CGI_CONTENT_LENGTH) ;length of post

;We read the buffer now
*Buffer = AllocateMemory(ContentLength)
Result= ReadConsoleData(*Buffer, ContentLength)


;Debug content
If DebugInput
 FF=CreateFile(#PB_Any,"test.hex")
 If FF
  WriteData(FF,*Buffer,ContentLength)
  CloseFile(FF)
 EndIf
EndIf

Info$ ="" 
NewList Arg.s()

If LCase(CGI_CONTENT_TYPE)="text/plain"
 InputBuffer$ = PeekS(*Buffer)
 ;MessageRequester("Info ",InputBuffer$,0)
 l=0
 Repeat
   l+1
   Argument.s=StringField(InputBuffer$,l, #CRLF$)
   AddElement(Arg())
   Arg()=LTrim(Argument)
 Until Argument.s=""
 
 ForEach Arg()
   Info$ + Arg() +  "<br>" ;Only for Debugging
 Next 
 
Else
 If Left(LCase(CGI_CONTENT_TYPE),Len("multipart/form-data"))="multipart/form-data"
  InputBuffer$ = PeekS(*Buffer);we can check that in a string, not secure, but works
  ;MessageRequester("Info ",InputBuffer$,0)
  Info$=InputBuffer$ 

  ;search For known patterns
   Res=FindString(InputBuffer$,"Content-Disposition:",1)
   If Res
    Res2=FindString(InputBuffer$,Chr(10),Res)
    If Res2
     ContentDisposition.s=Mid(InputBuffer$,Res,Res2-Res-1)
     ContentDisposition.s=Right(ContentDisposition.s,Len(ContentDisposition.s)-Len("Content-Disposition:"));shorten buffer
     l=0
     Repeat
      l+1
      Argument.s=StringField(ContentDisposition.s,l, ";")
      AddElement(Arg())
      Arg()=LTrim(Argument)
     Until Argument.s=""
    EndIf
   EndIf
   Res=FindString(InputBuffer$,"Content-Type:",1)
   If Res
    Res2=FindString(InputBuffer$,Chr(10),Res)
    If Res2
     ContentType.s=Mid(InputBuffer$,Res,Res2-Res-1)
     ContentType.s=Right(ContentType.s,Len(ContentType.s)-Len("Content-Type:"));shorten buffer
     Argument.s=StringField(ContentType.s,1, ";")
     AddElement(Arg())
     Arg()="Content-Type="+Argument
    EndIf
   EndIf
 
 
   ForEach Arg();iterate all arguments
    Info$ + Arg() +  "<br>" ;Only for Debugging
    ;MessageRequester("Info ","#" + arg()+"#",0)
    If Left(Arg(),9) = "filename="; oh , its a file to save
     ;MessageRequester("Info ","Saving File " + arg(),0)
     I=0
     I=FindString(InputBuffer$,Chr(13),I+1)
     I=FindString(InputBuffer$,Chr(13),I+1)
     I=FindString(InputBuffer$,Chr(13),I+1)
     I=FindString(InputBuffer$,Chr(13),I+1)
     If I>0
      Filename.s=Right(arg(),Len(Arg())-9)
      If Left(Filename.s,1)=Chr(34) :Filename.s=Right(Filename.s,Len(Filename.s)-1): EndIf
      If Right(Filename.s,1)=Chr(34) :Filename.s=Left(Filename.s,Len(Filename.s)-1): EndIf
      Filename=GetFilePart(Filename)
      Filename.s = Folder + Filename.s 
      FF=CreateFile(#PB_Any,Filename)
      If FF
       WriteData(FF,*Buffer+I+1,ContentLength-I)
       CloseFile(FF)
       info$ + " File saved under " + Filename + "<br>"
      Else
       info$ + " cannot create File under " + Filename + "<br>"
      EndIf 
     EndIf
    EndIf 
   Next
 
 Else
  ;what else a type ?  
  ;If = "application/octetstream"
 EndIf 
EndIf

FreeMemory(*Buffer);Free Buffer


HttpAnswer$ = OutputContentType.s + #CRLF$ + #CRLF$
HttpAnswer$ + "<html>"
HttpAnswer$ + "<header>"
HttpAnswer$ + "<title>" + AnswerTitle.s + "</title>"
HttpAnswer$ + "</header>"
HttpAnswer$ + "<body>"
HttpAnswer$ + "Hi, received your Data:<br>"

;we wanna show the cgi_Vars
Info$ + "<br>"
Info$ +  "CGI_AUTH_TYPE=" + CGI_AUTH_TYPE + "<br>"
Info$ +  "CGI_CONTENT_LENGTH=" + CGI_CONTENT_LENGTH + "<br>"
Info$ +  "CGI_CONTENT_TYPE=" + CGI_CONTENT_TYPE + "<br>"
Info$ +  "CGI_DOCUMENT_ROOT=" + CGI_DOCUMENT_ROOT + "<br>"
Info$ +  "CGI_GATEWAY_INTERFACE=" + CGI_GATEWAY_INTERFACE + "<br>"
Info$ +  "CGI_PATH_INFO=" + CGI_PATH_INFO + "<br>"
Info$ +  "CGI_PATH_TRANSLATED=" + CGI_PATH_TRANSLATED + "<br>"
Info$ +  "CGI_QUERY_STRING=" + CGI_QUERY_STRING + "<br>"
Info$ +  "CGI_REMOTE_ADDR=" + CGI_REMOTE_ADDR + "<br>"
Info$ +  "CGI_REMOTE_HOST=" + CGI_REMOTE_HOST + "<br>"
Info$ +  "CGI_REMOTE_IDENT=" + CGI_REMOTE_IDENT + "<br>"
Info$ +  "CGI_CGI_REMOTE_PORT=" + CGI_REMOTE_PORT + "<br>"
Info$ +  "CGI_REMOTE_USER=" + CGI_REMOTE_USER + "<br>"
Info$ +  "CGI_REQUEST_URI=" + CGI_REQUEST_URI + "<br>"
Info$ +  "CGI_REQUEST_METHOD=" + CGI_REQUEST_METHOD + "<br>"
Info$ +  "CGI_SCRIPT_NAME=" + CGI_SCRIPT_NAME + "<br>"
Info$ +  "CGI_SCRIPT_FILENAME=" + CGI_SCRIPT_FILENAME + "<br>"
Info$ +  "CGI_SERVER_ADMIN=" + CGI_SERVER_ADMIN + "<br>"
Info$ +  "CGI_SERVER_NAME=" + CGI_SERVER_NAME + "<br>"
Info$ +  "CGI_SERVER_PORT=" + CGI_SERVER_PORT + "<br>"
Info$ +  "CGI_SERVER_PROTOCOL=" + CGI_SERVER_PROTOCOL + "<br>"
Info$ +  "CGI_SERVER_SIGNATURE=" + CGI_SERVER_SIGNATURE + "<br>"
Info$ +  "CGI_SERVER_SOFTWARE=" + CGI_SERVER_SOFTWARE + "<br>" 
Info$ +  "CGI_HTTP_ACCEPT=" + CGI_HTTP_ACCEPT + "<br>"
Info$ +  "CGI_HTTP_ACCEPT_ENCODING=" + CGI_HTTP_ACCEPT_ENCODING + "<br>"
Info$ +  "CGI_HTTP_ACCEPT_LANGUAGE=" + CGI_HTTP_ACCEPT_LANGUAGE + "<br>"
Info$ +  "CGI_HTTP_COOKIE=" + CGI_HTTP_COOKIE + "<br>"
Info$ +  "CGI_HTTP_FORWARDED=" + CGI_HTTP_FORWARDED + "<br>"
Info$ +  "CGI_HTTP_HOST=" + CGI_HTTP_HOST + "<br>"
Info$ +  "CGI_HTTP_PRAGMA=" + CGI_HTTP_PRAGMA + "<br>"
Info$ +  "CGI_HTTP_REFERER=" + CGI_HTTP_REFERER + "<br>"
Info$ +  "CGI_HTTP_USER_AGENT=" + CGI_HTTP_USER_AGENT + "<br>"     

HttpAnswer$ + Info$

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

Written=WriteConsoleData(@HttpAnswer$, Len(HttpAnswer$)) ;write Data To console pipe 
; IDE Options = PureBasic v4.02 (Windows - x86)
; ExecutableFormat = Console
; CursorPosition = 4
; Folding = -
; Executable = C:\xampp\cgi-bin\CGIMIMAGE.exe
; DisableDebugger
Last edited by Rings on Thu Dec 21, 2006 4:21 pm, edited 2 times in total.
SPAMINATOR NR.1
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi Rings,

really nice job!

thanks for sharing.

a little change is needed on line 286 :-)

tested with "Sambar Server"
Best
jdp

Code: Select all

Folder.s="C:\upload\" 
      Filename.s=Right(arg(),Len(Arg())-9) 
      If Left(Filename.s,1)=Chr(34) :Filename.s=Right(Filename.s,Len(Filename.s)-1): EndIf 
      If Right(Filename.s,1)=Chr(34) :Filename.s=Left(Filename.s,Len(Filename.s)-1): EndIf 
      DateiName$ = GetFilePart(Filename)

      Filename.s = Folder + DateiName$
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

superB! :D

great job Rings.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

And for compile it in linux, what changes are needed?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

ricardo wrote:And for compile it in linux, what changes are needed?
There is a problem with line 210, with AllocateMemory, but i think this is the beta from PB
The other thing to change is line 299

Code: Select all

Beep_(100,100)
:wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> There is a problem with line 210, with AllocateMemory, but i think this is the beta from PB

Read the error message: it only happens when you allocate a buffer of size 0.
This should be checked in the code.

Remove the beep and change all the paths (C:\...) to something linux like, and it works well.
quidquid Latine dictum sit altum videtur
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

great tips, thanx

but it might be good to convert the output to utf-8 before using writeconsoledata()
then it can be compiled in unicode mode also.
it would also need this changed:
Content-type: text/html
to
Content-type: text/html;charset=UTF-8
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

Edited the source-example
SPAMINATOR NR.1
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post by thanos »

@Rings
Thank you very much for this excellent code!
I tested it out and it worked okay.
But when i did input unicode characters in the boxes the results was bad.
I tried to compile this source as unicode executable but the browser does not recognize the header. I took the following message:

Code: Select all

Server error!
    The server encountered an internal error and was 
    unable to complete your request.
    Error message:
    malformed header from script. Bad header=C: cgimimage.exe
If you think this is a server error, please contact
the mailto:admin@localhost
Error 500
08/17/08 20:10:47
Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5
BTW i compiled this code with Linux version of PureBasic and it was run perfecty (except the problem with unicode characters).
Do you have any idea how to fix this problem?
Regards.

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

you would need to change

Code: Select all

Written=WriteConsoleData(@HttpAnswer$, Len(HttpAnswer$))
to something like:

Code: Select all

utf8len = StringByteLength(HttpAnswer$, #PB_UTF8)
*utf8 = AllocateMemory(utf8len+1)
PokeS(*utf8, HttpAnswer$, -1, #PB_UTF8)
Written=WriteConsoleData(*utf8, utf8len)
FreeMemory(*utf8)
if you compile it in unicode mode
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post by thanos »

@lexvictory

Thank you for the reply.
I will check out this code.
Regards.

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post by thanos »

It is working!
But, when i input UTF-8 characteres i take really bad results.
For example, i input the following string in the form:
Όνομα Επώνυμο (which is a string in the Greek language)

and i took the following results:
Hi, received your Data:
㉐䵟呹硥㵴붌벿₱삕뷎볅඿

What is wrong?
Please mention that the character encoding in browser is Unicode (UTF8).
Regards.

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

thanos wrote:What is wrong?
the server is sending the postdata to to console as UTF8, so it needs to be read like that.

also to post unicode data, the enctype="text/plain" needs to be removed from the form tags, so then the browser (firefox at least) sends the data url encoded.

here is the code that i use for the cgi:

Code: Select all

;CGI-Example for Web-server using
; native Purebasic, tested with apache
; (C) 2006 by Siegfried Rings
; free for use,
; but forbidden to making shitty non-source librarys from !
; and also forbidden to make shitty source-collections from (Except my permission)
; and also PLZ do Not Remove this shitty Header ;) !!!!

;Compile as Console-Exe

;ToDo: A Lot, the filsize is not exactly
;      Test with other servers


;OutputContentType.s="Content-type: text/html"
OutputContentType.s="Content-type: text/html; charset=UTF-8"
AnswerTitle.s="Answer from PureBasic-CGI"

Folder.s=""; "C:"
DebugInput=0

Global CGI_AUTH_TYPE.s
Global CGI_CONTENT_LENGTH.s
Global CGI_CONTENT_TYPE.s
Global CGI_DOCUMENT_ROOT.s
Global CGI_GATEWAY_INTERFACE.s
Global CGI_PATH_INFO.s
Global CGI_PATH_TRANSLATED.s
Global CGI_QUERY_STRING.s
Global CGI_REMOTE_ADDR.s
Global CGI_REMOTE_HOST.s
Global CGI_REMOTE_IDENT.s
Global CGI_REMOTE_PORT.s
Global CGI_REMOTE_USER.s
Global CGI_REQUEST_URI.s
Global CGI_REQUEST_METHOD.s
Global CGI_SCRIPT_NAME.s
Global CGI_SCRIPT_FILENAME.s
Global CGI_SERVER_ADMIN.s
Global CGI_SERVER_NAME.s
Global CGI_SERVER_PORT.s
Global CGI_SERVER_PROTOCOL.s
Global CGI_SERVER_SIGNATURE.s
Global CGI_SERVER_SOFTWARE.s
Global CGI_HTTP_ACCEPT.s
Global CGI_HTTP_ACCEPT_ENCODING.s
Global CGI_HTTP_ACCEPT_LANGUAGE.s
Global CGI_HTTP_COOKIE.s
Global CGI_HTTP_FORWARDED.s
Global CGI_HTTP_HOST.s
Global CGI_HTTP_PRAGMA.s
Global CGI_HTTP_REFERER.s
Global CGI_HTTP_USER_AGENT.s

Procedure Get_CGI_Var()
;     * AUTH_TYPE - Describes the authentication method used by the web browser If any authentication method was used. This is Not set unless the script is Protected.
CGI_AUTH_TYPE  = GetEnvironmentVariable("AUTH_TYPE")   


;     * CONTENT_LENGTH - This is used For scripts that are receiving form Data using the POST method. This variable tells the byte length of the CGI input Data stream. This is required To Read the Data from the standard input With the POST method.
CGI_CONTENT_LENGTH  = GetEnvironmentVariable("CONTENT_LENGTH")   


;     * CONTENT_TYPE - Tells the media type of Data being received from the user. this is used For scripts called using the POST method.
CGI_CONTENT_TYPE  = GetEnvironmentVariable("CONTENT_TYPE")   


;     * DOCUMENT_ROOT - The root path To the home HTML page For the server. Example:
;       /home/httpd/html
CGI_DOCUMENT_ROOT  = GetEnvironmentVariable("DOCUMENT_ROOT")   


;     * GATEWAY_INTERFACE - The version of the common gateway Interface (CGI) specification being used To exchange the Data between the client And server. this is normally CGI/1.1 For the current revision level of 1.1.
;   Example:   CGI/1.1
CGI_GATEWAY_INTERFACE  = GetEnvironmentVariable("GATEWAY_INTERFACE")   


;     * PATH_INFO - Extra path information added To the End of the URL that accessed the server side script program.
CGI_PATH_INFO  = GetEnvironmentVariable("PATH_INFO")   


;     * PATH_TRANSLATED - A translated version of the PATH_INFO variable translated by the webserver from virtual To physical path information.
CGI_PATH_TRANSLATED  = GetEnvironmentVariable("PATH_TRANSLATED")   


;     * QUERY_STRING - This string contains any information at the End of the server side script path that followed a question mark. Used To Return Data If the GET method was used by a form. There are length restrictions To the QUERY_STRING. Example of how To set it in HTML:
;       <A HREF="/cgi-bin/hits.pl?mainpage></A>
;       The information after the ? is the QUERY_STRING which is "mainpage" in this Case. How it looks on the server side
;       mainpage
CGI_QUERY_STRING  = GetEnvironmentVariable("QUERY_STRING")   


;     * REMOTE_ADDR - The IP address of the client computer. Example:
;       132.15.28.124
CGI_REMOTE_ADDR  = GetEnvironmentVariable("REMOTE_ADDR")   



;     * REMOTE_HOST - The fully qualified domain name of the client machine making the HTTP request. It may Not be possible To determine this name since many client computers names are Not recorded in the DNS system. Example:
;       comp11.mycompanyproxy.com
CGI_REMOTE_HOST  = GetEnvironmentVariable("REMOTE_HOST")   


;     * REMOTE_IDENT - The ability To use this variable is limited To servers that support RFC 931. This variable may contain the client machine's username, but it is intended to be used for logging purposes only, when it is available.
CGI_REMOTE_IDENT  = GetEnvironmentVariable("REMOTE_IDENT")   


;     * REMOTE_PORT - The clients requesting port. An example:
;       3465
CGI_REMOTE_PORT  = GetEnvironmentVariable("REMOTE_PORT")   


;     * REMOTE_USER - If the CGI script was Protected And the user had To be logged in To get access To the script, this value will contain the user's log in name
CGI_REMOTE_USER  = GetEnvironmentVariable("REMOTE_USER")   


;     * REQUEST_URI - The path To the requested file by the client. An example:
;       /cgi-bin/join.pl?button=on
CGI_REQUEST_URI  = GetEnvironmentVariable("REQUEST_URI")   


;     * REQUEST_METHOD - This describes the request method used by the browser which is normally GET, POST, Or HEAD.
CGI_REQUEST_METHOD  = GetEnvironmentVariable("REQUEST_METHOD")   


;     * SCRIPT_NAME - The virtual path of the CGI script being executed. Example:
;       /cgi-bin/join.pl
CGI_SCRIPT_NAME  = GetEnvironmentVariable("SCRIPT_NAME")   


;     * SCRIPT_FILENAME - Example:
;       /home/httpd/cgi-bin/join.pl
CGI_SCRIPT_FILENAME  = GetEnvironmentVariable("SCRIPT_FILENAME")   

;     * SERVER_ADMIN - The e-mail address of the server administrator. Example:
;       webadmin@myhost.mycompany.org
CGI_SERVER_ADMIN  = GetEnvironmentVariable("SERVER_ADMIN")   


;     * SERVER_NAME - The server hostname, IP address Or DNS alias name shown As a self referencing URL. This does Not include the protocol identifier such As "HTTP:", the machine name, Or port number. Example:
;       myhost
CGI_SERVER_NAME  = GetEnvironmentVariable("SERVER_NAME")   


;     * SERVER_PORT - The port number the HTTP requests And responses are being sent on. Example:
;       80
CGI_SERVER_PORT  = GetEnvironmentVariable("SERVER_PORT")   


;     * SERVER_PROTOCOL - This value is normally HTTP which describes the protocol being used between the client And server computers. Example:
;       HTTP/1.1
CGI_SERVER_PROTOCOL  = GetEnvironmentVariable("SERVER_PROTOCOL")   


;     * SERVER_SIGNATURE - Server information specifying the name And version of the web server And the port being serviced. Example:
;       Apache/1.3.12 Server at mdct-dev3 Port 80
CGI_SERVER_SIGNATURE  = GetEnvironmentVariable("SERVER_SIGNATURE")   


;     * SERVER_SOFTWARE - The name And version of the web server. Example:
;       Apache/1.3.12 (Unix) (Red Hat/Linux) PHP/3.0.15 mod_perl/1.21
CGI_SERVER_SOFTWARE  = GetEnvironmentVariable("SERVER_SOFTWARE")     


;     * HTTP_ACCEPT - The media types of Data that the client browser can accept. these Data types are separated by commas. An example:
;       image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*
CGI_HTTP_ACCEPT  = GetEnvironmentVariable("HTTP_ACCEPT")   


;     * HTTP_ACCEPT_ENCODING An example:
;       gzip, deflate
CGI_HTTP_ACCEPT_ENCODING  = GetEnvironmentVariable("HTTP_ACCEPT_ENCODING")   


;     * HTTP_ACCEPT_LANGUAGE - The language the client browser accepts. Example:
;       en-us
CGI_HTTP_ACCEPT_LANGUAGE  = GetEnvironmentVariable("HTTP_ACCEPT_LANGUAGE")   


;     * HTTP_COOKIE - Used As an environment variable that contains cookies associated With the server domain from the browser.
CGI_HTTP_COOKIE  = GetEnvironmentVariable("HTTP_COOKIE")   


;     * HTTP_FORWARDED An example:
;       by http://proxy-nt1.yourcompany.org:8080 (Netscape-Proxy/3.5)
CGI_HTTP_FORWARDED  = GetEnvironmentVariable("HTTP_FORWARDED")   


;     * HTTP_HOST An example:
;       yourwebhost.yourcompany.org
CGI_HTTP_HOST  = GetEnvironmentVariable("HTTP_HOST")   


;     * HTTP_PRAGMA - An example:
;       No-Cache
CGI_HTTP_PRAGMA  = GetEnvironmentVariable("HTTP_PRAGMA")   


;     * HTTP_REFERER - The page address where the HTTP request originated. An example:
;       http://ctdp.tripod.com/independent/web/cgi/cgimanual/index.html
CGI_HTTP_REFERER  = GetEnvironmentVariable("HTTP_REFERER")   


;     * HTTP_USER_AGENT - The name of the client web browser being used To make the request. Example:
;       Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)
CGI_HTTP_USER_AGENT  = GetEnvironmentVariable("HTTP_USER_AGENT")

EndProcedure

ProcedureDLL.l MyHex2Dec(hex.s);netmaestro's code with little endian conversion
  ;convert to Little Endian
  tmp.s = ""
  For i=1 To 7 Step 2
    tmp=Mid(hex,i,2)+tmp
  Next
  hex=tmp
  result.l = 0
  multiplier = 1
  For i = Len(hex) To 1 Step -1
    Select UCase(Mid(hex, i, 1))
      Case "A":temp=10
      Case "B":temp=11
      Case "C":temp=12
      Case "D":temp=13
      Case "E":temp=14
      Case "F":temp=15
      Default : temp = Val(Mid(hex, i, 1))
    EndSelect
    result + temp * multiplier
    multiplier * 16
  Next
  ProcedureReturn result
EndProcedure 

Structure bytes
a.b
EndStructure

Procedure.s unescape(escaped.s); PB's function doesnt handle utf8 properly.
string2.s = Space(Len(escaped))
PokeS(@string2, escaped, -1, #PB_UTF8)

*thing.bytes = @string2
resultutf8.s = Space(Len(escaped))
*result.bytes = @resultutf8

For x = 0 To MemoryStringLength(@string2, #PB_UTF8)
  If *thing\a = 0;null
    *result\a = 0
    Break
  ElseIf *thing\a = 37;%
    hexbit.s = ""
    *thing+1
    hexbit+Chr(*thing\a)
    *thing+1
    hexbit+Chr(*thing\a)
    *result\a = myhex2dec(hexbit)
  ElseIf *thing\a = 43;+
    *result\a = 32;change it to a space
  Else
    *result\a = *thing\a
  EndIf
  
  *thing+1
  *result+1
Next x

ProcedureReturn PeekS(@resultutf8, -1, #PB_UTF8)
EndProcedure

OpenConsole() ;Needed For Output
EnableGraphicalConsole(0) ;set for redirecting

;Letz do some basic CGI-Stuff, get all those environment variables
Get_CGI_Var()

ContentLength = Val(CGI_CONTENT_LENGTH) ;length of post

;We read the buffer now
*Buffer = AllocateMemory(ContentLength)
Result= ReadConsoleData(*Buffer, ContentLength)


;Debug content
If DebugInput
 FF=CreateFile(#PB_Any,"test.hex")
 If FF
  WriteData(FF,*Buffer,ContentLength)
  CloseFile(FF)
 EndIf
EndIf

Info$ =""
NewList Arg.s()

If LCase(CGI_CONTENT_TYPE)="text/plain" Or LCase(CGI_CONTENT_TYPE)="application/x-www-form-urlencoded"
  If LCase(CGI_CONTENT_TYPE)="application/x-www-form-urlencoded"
    InputBuffer$ = unescape(PeekS(*Buffer, ContentLength, #PB_UTF8))
  Else
    InputBuffer$ = PeekS(*Buffer, -1, #PB_UTF8)
  EndIf
 ;MessageRequester("Info ",InputBuffer$,0)
 l=0
 Repeat
   l+1
   Argument.s=StringField(InputBuffer$,l, #CRLF$)
   AddElement(Arg())
   Arg()=LTrim(Argument)
 Until Argument.s=""
 
 ForEach Arg()
   Info$ + Arg() +  "<br>" ;Only for Debugging
 Next
 
Else
 If Left(LCase(CGI_CONTENT_TYPE),Len("multipart/form-data"))="multipart/form-data"
  InputBuffer$ = PeekS(*Buffer, ContentLength, #PB_UTF8);we can check that in a string, not secure, but works
  ;MessageRequester("Info ",InputBuffer$,0)
  Info$=InputBuffer$

  ;search For known patterns
   Res=FindString(InputBuffer$,"Content-Disposition:",1)
   If Res
    Res2=FindString(InputBuffer$,Chr(10),Res)
    If Res2
     ContentDisposition.s=Mid(InputBuffer$,Res,Res2-Res-1)
     ContentDisposition.s=Right(ContentDisposition.s,Len(ContentDisposition.s)-Len("Content-Disposition:"));shorten buffer
     l=0
     Repeat
      l+1
      Argument.s=StringField(ContentDisposition.s,l, ";")
      AddElement(Arg())
      Arg()=LTrim(Argument)
     Until Argument.s=""
    EndIf
   EndIf
   Res=FindString(InputBuffer$,"Content-Type:",1)
   If Res
    Res2=FindString(InputBuffer$,Chr(10),Res)
    If Res2
     ContentType.s=Mid(InputBuffer$,Res,Res2-Res-1)
     ContentType.s=Right(ContentType.s,Len(ContentType.s)-Len("Content-Type:"));shorten buffer
     Argument.s=StringField(ContentType.s,1, ";")
     AddElement(Arg())
     Arg()="Content-Type="+Argument
    EndIf
   EndIf
 
 
   ForEach Arg();iterate all arguments
    Info$ + Arg() +  "<br>" ;Only for Debugging
    ;MessageRequester("Info ","#" + arg()+"#",0)
    If Left(Arg(),9) = "filename="; oh , its a file to save
     ;MessageRequester("Info ","Saving File " + arg(),0)
     I=0
     I=FindString(InputBuffer$,Chr(13),I+1)
     I=FindString(InputBuffer$,Chr(13),I+1)
     I=FindString(InputBuffer$,Chr(13),I+1)
     I=FindString(InputBuffer$,Chr(13),I+1)
     If I>0
      Filename.s=Right(arg(),Len(Arg())-9)
      If Left(Filename.s,1)=Chr(34) :Filename.s=Right(Filename.s,Len(Filename.s)-1): EndIf
      If Right(Filename.s,1)=Chr(34) :Filename.s=Left(Filename.s,Len(Filename.s)-1): EndIf
      Filename=GetFilePart(Filename)
      Filename.s = Folder + Filename.s
      FF=CreateFile(#PB_Any,Filename)
      If FF
       WriteData(FF,*Buffer+I+1,ContentLength-I)
       CloseFile(FF)
       info$ + " File saved under " + Filename + "<br>"
      Else
       info$ + " cannot create File under " + Filename + "<br>"
      EndIf
     EndIf
    EndIf
   Next
 
 Else
  ;what else a type ? 
  ;If = "application/octetstream"
 EndIf
EndIf

FreeMemory(*Buffer);Free Buffer


HttpAnswer$ = OutputContentType.s + #CRLF$ + #CRLF$
HttpAnswer$ + "<html>"
HttpAnswer$ + "<header>"
HttpAnswer$ + "<title>" + AnswerTitle.s + "</title>"
HttpAnswer$ + "</header>"
HttpAnswer$ + "<body>"
HttpAnswer$ + "Hi, received your Data:<br>"

;we wanna show the cgi_Vars
Info$ + "<br>"
Info$ +  "CGI_AUTH_TYPE=" + CGI_AUTH_TYPE + "<br>"
Info$ +  "CGI_CONTENT_LENGTH=" + CGI_CONTENT_LENGTH + "<br>"
Info$ +  "CGI_CONTENT_TYPE=" + CGI_CONTENT_TYPE + "<br>"
Info$ +  "CGI_DOCUMENT_ROOT=" + CGI_DOCUMENT_ROOT + "<br>"
Info$ +  "CGI_GATEWAY_INTERFACE=" + CGI_GATEWAY_INTERFACE + "<br>"
Info$ +  "CGI_PATH_INFO=" + CGI_PATH_INFO + "<br>"
Info$ +  "CGI_PATH_TRANSLATED=" + CGI_PATH_TRANSLATED + "<br>"
Info$ +  "CGI_QUERY_STRING=" + CGI_QUERY_STRING + "<br>"
Info$ +  "CGI_REMOTE_ADDR=" + CGI_REMOTE_ADDR + "<br>"
Info$ +  "CGI_REMOTE_HOST=" + CGI_REMOTE_HOST + "<br>"
Info$ +  "CGI_REMOTE_IDENT=" + CGI_REMOTE_IDENT + "<br>"
Info$ +  "CGI_CGI_REMOTE_PORT=" + CGI_REMOTE_PORT + "<br>"
Info$ +  "CGI_REMOTE_USER=" + CGI_REMOTE_USER + "<br>"
Info$ +  "CGI_REQUEST_URI=" + CGI_REQUEST_URI + "<br>"
Info$ +  "CGI_REQUEST_METHOD=" + CGI_REQUEST_METHOD + "<br>"
Info$ +  "CGI_SCRIPT_NAME=" + CGI_SCRIPT_NAME + "<br>"
Info$ +  "CGI_SCRIPT_FILENAME=" + CGI_SCRIPT_FILENAME + "<br>"
Info$ +  "CGI_SERVER_ADMIN=" + CGI_SERVER_ADMIN + "<br>"
Info$ +  "CGI_SERVER_NAME=" + CGI_SERVER_NAME + "<br>"
Info$ +  "CGI_SERVER_PORT=" + CGI_SERVER_PORT + "<br>"
Info$ +  "CGI_SERVER_PROTOCOL=" + CGI_SERVER_PROTOCOL + "<br>"
Info$ +  "CGI_SERVER_SIGNATURE=" + CGI_SERVER_SIGNATURE + "<br>"
Info$ +  "CGI_SERVER_SOFTWARE=" + CGI_SERVER_SOFTWARE + "<br>"
Info$ +  "CGI_HTTP_ACCEPT=" + CGI_HTTP_ACCEPT + "<br>"
Info$ +  "CGI_HTTP_ACCEPT_ENCODING=" + CGI_HTTP_ACCEPT_ENCODING + "<br>"
Info$ +  "CGI_HTTP_ACCEPT_LANGUAGE=" + CGI_HTTP_ACCEPT_LANGUAGE + "<br>"
Info$ +  "CGI_HTTP_COOKIE=" + CGI_HTTP_COOKIE + "<br>"
Info$ +  "CGI_HTTP_FORWARDED=" + CGI_HTTP_FORWARDED + "<br>"
Info$ +  "CGI_HTTP_HOST=" + CGI_HTTP_HOST + "<br>"
Info$ +  "CGI_HTTP_PRAGMA=" + CGI_HTTP_PRAGMA + "<br>"
Info$ +  "CGI_HTTP_REFERER=" + CGI_HTTP_REFERER + "<br>"
Info$ +  "CGI_HTTP_USER_AGENT=" + CGI_HTTP_USER_AGENT + "<br>"     

HttpAnswer$ + Info$

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

utf8len = StringByteLength(HttpAnswer$, #PB_UTF8)
*utf8 = AllocateMemory(utf8len+1)
PokeS(*utf8, HttpAnswer$, -1, #PB_UTF8)
Written=WriteConsoleData(*utf8, utf8len)
FreeMemory(*utf8)
and the html code:

Code: Select all

<html>
<head>
<title>Enter some data for me</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<H3>MultiImage Request Form cgitest</H3>
<P>
<FORM ACTION="/path/to/cgi" 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>

<FORM name="textsending_easy" ACTION="/path/to/cgi" METHOD="POST">
<INPUT TYPE=Text Name="P2_MyText" Value="Type some stuff to send here" SIZE=35 MAXLENGTH=50></P>
<P>
<INPUT TYPE="submit" VALUE="Send the Text">
</P>
</FORM>


<form name="Layoutbereich1FORM" action="/path/to/cgi"  method="post">
using Purebasic<input id="Formularmarkierungsfeld1" name="Purebasic" value="yes" type="checkbox"><br>
using VB<input id="Formularmarkierungsfeld2" name="Visual Basic" value="holla" type="checkbox"><br>
using DotNet<input id="Formularmarkierungsfeld3" name="VB.NET" value="uups" type="checkbox"><br>
Use other stuff<input id="Formularmarkierungsfeld4" name="Other" value="ok" type="checkbox"><br>
your name<input id="Formulareditierfeld5" name="NickName" value="RINGS" size="40" maxlength="40" type="text"><br>
your email<input id="Formulareditierfeld6" name="email-addi" value="karl@nospam.fr" size="43" maxlength="43" type="text"><br>
<input name="FormularHandler1" value="Sending" id="FormularHandler1" type="submit"></td>
</form> 
</body></html>
coded and tested on linux - windows should be the same
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post by thanos »

lexvictory wrote:the server is sending the postdata to to console as UTF8, so it needs to be read like that.

also to post unicode data, the enctype="text/plain" needs to be removed from the form tags, so then the browser (firefox at least) sends the data url encoded.

coded and tested on linux - windows should be the same
The new code is working perfectly!
Thank you very much.
Regards.

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: CGI Using in Native Purebasic

Post by netmaestro »

Thanks for this code Rings, it's just what I'm looking for right now. I tried to get it working with IIS7 but it wouldn't work, complaining of illegal HTTP verb being used. I don't like IIS anyway so I uninstalled it and installed Apache. Now it works well and I can go on to modify the Purebasic code to open a database and save answers in it.

Good job, thanks again :mrgreen:
BERESHEIT
Post Reply