Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Support

Pages: 1 ... 10 11 [12]
166
ScriptBasic Examples w/source / Password Entry Example
« on: March 26, 2006, 08:28:43 pm »
http://www.scriptbasic.org/cgi-bin/getpswd.bas

Code: [Select]

#!/usr/bin/scriba -c

INCLUDE cgi.bas

OPTION cgi$Method cgi::Post or cgi::Get

IF cgi::RequestMethod()="GET" THEN
  max_tries = 5
  tryno=1
  mypass = ""
END IF

IF cgi::RequestMethod()="POST" THEN
  IF cgi::PostParam("mypass")="LetMeIn" THEN
    cgi::Header 302,"text/html"
    PRINT "Location: /private.html\n"
    cgi::FinishHeader
    END
  END IF
  max_tries=cgi::PostParam("max_tries")
  tryno=cgi::PostParam("tryno")
  tryno = tryno + 1
  IF tryno > val(max_tries) THEN
    cgi::Header 302,"text/html"
    PRINT "Location: /home.html\n"
    cgi::FinishHeader
    END  
  END IF
END IF
cgi::Header 200,"text/html"
cgi::FinishHeader

PRINT """
<html>

Try number """ & tryno & """<br>

Enter Passsword:

<form method=post action=/cgi-bin/getpswd.bas>
  <input type=password name=mypass size=10>
  <input type=submit value="Go">
  <input type=hidden name=max_tries value=""" & max_tries & """>
  <input type=hidden name=tryno value=""" & tryno & """>
</form>
</html>
"""
END


--------------------------[home.html]------------------------------

<html>
<h1>Home Page</h1>
</html>

--------------------------[private.html]----------------------------

<html>
<h1>Private Page</h1>
</html>

167
ScriptBasic Examples w/source / CGI - ODBC Example
« on: March 26, 2006, 05:45:03 pm »
Code: Script BASIC
  1. #!/usr/bin/scriba -c
  2.  
  3. INCLUDE cgi.bas
  4. INCLUDE odbc.bas
  5.  
  6. cgi::Header 200,"text/html"
  7. cgi::FinishHeader
  8.  
  9. PRINT """
  10. <HTML>
  11. <HEAD>
  12. <title>unixODBC testing</title>
  13. </HEAD>
  14. <BODY>
  15. <FONT face="Verdana, Arial, Helvetica, sans-serif">
  16. <TABLE border="1" cellpadding="3">
  17. """
  18.  
  19. ON ERROR GOTO PROBLEMS
  20.  
  21. dbh = ODBC::RealConnect("DSN","user","password")
  22.  
  23. ODBC::query(dbh,"SELECT * FROM contact")
  24.  
  25. PRINT "File Handle: <b>",dbh,"</b><br>"
  26. PRINT "Affected Rows: <b>",ODBC::AffectedRows(dbh),"</b><br>"
  27.  
  28. WHILE ODBC::FetchHash(dbh,column)
  29.  
  30. PRINT "<TR>"
  31. PRINT "<TD>",column{"ID"},"</TD>"
  32. PRINT "<TD>",column{"NAME"},"</TD>"
  33. PRINT "<TD>",column{"ADDRESS"},"</TD>"
  34. PRINT "<TD>",column{"CITY"},"</TD>"
  35. PRINT "<TD>",column{"STATE"},"</TD>"
  36. PRINT "<TD>",column{"ZIP"},"</TD>"
  37. PRINT "<TD>",column{"PHONE"},"</TD>"
  38. PRINT "<TD>",column{"EMAIL"},"</TD>"
  39. PRINT "<TD>",column{"URL"},"</TD>"
  40. PRINT "</TR>"
  41.  
  42. WEND
  43.  
  44. PRINT """
  45. </TABLE>
  46. </FONT>
  47. </BODY>
  48. </HTML>
  49. """
  50.  
  51. ODBC::Close(dbh)
  52.  
  53. END
  54.  
  55. PROBLEMS:
  56.  
  57. PRINT "ERROR = ",error(),"<br>"
  58.  
  59. RESUME
  60.  

168
ScriptBasic Examples w/source / CGI - MySQL Example
« on: March 26, 2006, 05:42:01 pm »


Code: [Select]
#!/usr/bin/scriba -c

INCLUDE cgi.bas
INCLUDE mysql.bas

OPTION cgi$Method cgi::Post or cgi::Get

dbh = mysql::RealConnect("host","user","password","database")

mysql::query(dbh,"SELECT * FROM contact")

cgi::Header 200,"text/html"

cgi::FinishHeader

PRINT """
<HTML>
<HEAD>
<title>mySQL testing</title>
</HEAD>
<BODY>
"""
PRINT """<FONT face="Verdana, Arial, Helvetica, sans-serif">"""

PRINT """<TABLE border="1" cellpadding="3">"""

WHILE mysql::FetchHash(dbh,column)

PRINT "<TR>"
PRINT "<TD>",column{"ID"},"</TD>"
PRINT "<TD>",column{"NAME"},"</TD>"
PRINT "<TD>",column{"ADDRESS"},"</TD>"
PRINT "<TD>",column{"CITY"},"</TD>"
PRINT "<TD>",column{"STATE"},"</TD>"
PRINT "<TD>",column{"ZIP"},"</TD>"
PRINT "<TD>",column{"PHONE"},"</TD>"
PRINT "<TD>",column{"EMAIL"},"</TD>"
PRINT "<TD>",column{"URL"},"</TD>"
PRINT "</TR>"

WEND

PRINT "</TABLE>"

PRINT "<BR>"
PRINT "The database handle is: <b>",dbh,"</b><BR>"
PRINT "Affected rows by SELECT: <b>",mysql::AffectedRows(dbh),"</b><BR>"
PRINT "Character set name is: <b>",mysql::CharacterSetName(dbh),"</b><BR>"
PRINT "Last error is: <b>",mysql::ErrorMessage(dbh),"</b><BR>"
PRINT "Client info is: <b>",mysql::GetClientInfo(),"</b><BR>"
PRINT "Host info is: <b>",mysql::GetHostInfo(dbh),"</b><BR>"
PRINT "Proto info is: <b>",mysql::GetProtoInfo(dbh),"</b><BR>"
PRINT "Server info is: <b>",mysql::GetServerInfo(dbh),"</b><BR>"
PRINT "PING result: <b>",mysql::Ping(dbh),"</b><BR>"
PRINT "Thread ID: <b>",mysql::ThreadId(dbh),"</b><BR>"
PRINT "Status is: <b>",mysql::Stat(dbh),"</b><BR>"

PRINT "</FONT>"

PRINT """
</BODY>
</HTML>
"""

mysql::Close(dbh)

END

169
ScriptBasic Examples w/source / CGI - echo.bas
« on: March 26, 2006, 05:36:09 pm »
This example posts to itself so you can see some of the features of the CGI extension module.

http://www.scriptbasic.org/cgi-bin/echo.bas

Code: [Select]
#! /usr/bin/scriba -c
global const nl = "\n"
Const NumberOfCookies = 3

include cgi.bas

option cgi$Method cgi::Get or cgi::Upload

' cgi::RequestBasicAuthentication "login password"
cgi::Header 200,"text/html"

'
' We are setting several cookies. The expiry time is ten seconds so you can test that
' the cookies are sent by the browser if you press some of the buttons fast enough,
' but it does not if you are slow
'
for i=1 to NumberOfCookies
  ' cookie(i) is i, no domain is defined, path is /, expires after 10 seconds, not secure
  cgi::SetCookie "cookie" & i,i,undef,"/",gmtime()+10,false
next i

cgi::FinishHeader

'-------------------------------------------------------
print """<HTML>
<HEAD>
<title>CGI parameter testing</title>
</HEAD>
<BODY><font face="VERDANA" size="2">
<H1>View CGI Parameters</H1>
This page shows the cgi parameters the way it was uploaded.
<!-- here is the result of the previous HTTP request -->
<FONT SIZE="3">
<PRE>

CGI system variables
--------------------

"""
'-------------------------------------------------------

print "ServerSoftware  = ",cgi::ServerSoftware(), nl
print "ServerName      = ",cgi::ServerName(), nl
print "GatewayInterface= ",cgi::GatewayInterface(),nl
print "ServerProtocol  = ",cgi::ServerProtocol(), nl
print "ServerPort      = ",cgi::ServerPort(), nl
print "RequestMethod   = ",cgi::RequestMethod(), nl
print "PathInfo        = ",cgi::PathInfo(), nl
print "PathTranslated  = ",cgi::PathTranslated(), nl
print "ScriptName      = ",cgi::ScriptName(), nl
print "QueryString     = ",cgi::QueryString(), nl
print "RemoteHost      = ",cgi::RemoteHost(), nl
print "RemoteAddress   = ",cgi::RemoteAddress(), nl
print "AuthType        = ",cgi::AuthType(), nl
print "RemoteUser      = ",cgi::RemoteUser(), nl
print "RemoteIdent     = ",cgi::RemoteIdent(), nl
print "ContentType     = ",cgi::ContentType(), nl
print "ContentLength   = ",cgi::ContentLength(), nl
print "UserAgent       = ",cgi::UserAgent(), nl
print "Cookie          = ",cgi::RawCookie(), nl

print "Referer         = ",cgi::Referer(),nl
print "Password        = ",Environ("HTTP_PASSWORD"),nl
print "Full auth string= ",Environ("HTTP_AUTHORIZATION"),nl
print "\nCookies:\n"
for i=1 to NumberOfCookies
  print "cookie" & i," ",cgi::Cookie("cookie" & i),"\n"
next i

print "Text field using Param(\"TEXT-FIELD\") is ",cgi::Param("TEXT-FIELD"),nl,nl


if cgi::RequestMethod() = "GET" then
  print "GET text field using GetParam(\"TEXT-FIELD\") is ",cgi::GetParam("TEXT-FIELD"),nl
end if

if cgi::RequestMethod() = "POST" then
  print "POST text field using PostParam(\"TEXT-FIELD\") is ",cgi::PostParam("TEXT-FIELD"),nl
  if cgi::ContentType() like "multipart*" then
    print "Original file name is ",cgi::FileName("FILE-UPLOAD-NAME"),nl
    if cgi::FileLength("FILE-UPLOAD-NAME") > 0 then
      print "File with a length of ",cgi::FileLength("FILE-UPLOAD-NAME")," bytes was saved\n"
      on error goto NoSave
      cgi::SaveFile "FILE-UPLOAD-NAME","/var/www/vhosts/scriptbasic.org/httpdocs/upload/newup.txt"
    else
      print "There is no uploaded file."
    end if
  end if
end if

print """</PRE><TABLE><TR><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to POST parameters:<BR>
<FORM METHOD="POST" ACTION="/cgi-bin/echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" POST ">
</FORM>
</PRE></TD><TD BORDER=1 width="20">&nbsp;</TD><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to GET parameters:<BR>
<FORM METHOD="GET" ACTION="/cgi-bin/echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" GET ">
</FORM>
</PRE></TD></TR></TABLE><PRE>
<hr>
A simple form to UPLOAD a file:<BR>
<FORM METHOD="POST" ACTION="/cgi-bin/echo.bas" ENCTYPE="multipart/form-data">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="FILE" VALUE="FILE-UPLOAD-VALUE" NAME="FILE-UPLOAD-NAME">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE="UPLOAD FILE">
</FORM>
<hr>
</BODY>
</HTML>
"""
stop
NoSave:

print "An error has happened saving the file. Code =",error(),nl

resume next

John

Pages: 1 ... 10 11 [12]