Announcement

Collapse
No announcement yet.

CGI Tutorial Part 2

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Joe Byrne
    replied
    Originally posted by tom kroto View Post
    Another dumb question:
    I read your tutorial and all the replies but I still have this question:
    If I can test the .htm locally i.e. by using file>open>browse and finding the .htm on my laptop, why can't I run the CGI you supplied locally too?
    Thanks.
    An HTML page is 'static'. The html file contains all the formatting code and data necessary for the web browser to display it.

    A CGI application is a server-based program that feeds dynamic data to the web server to be sent back to the browser.

    The CGI application doesn't 'talk' directly to the web browser, it needs the web server to accept the data from the cgi application and then pass it on to the browser.

    IF you're CGI application actually created a file on your disk, you could 'open' it directly because the contents of that file would be static HTML information. However, to be useful, you want the cgi application to be more-or-less interactive so you don't have to keep creating disk files and requesting them individually from your browser. You want the cgi application to create HTML code that is sent directly to your browser for display. This can only be done with a server that manages the requests from the browser and the responses from the cgi applications.

    For debugging, you can easily install a simple web server on your local PC. In fact, there are lots of WAMP packages (Windows Apache/MySQL/PHP) you can install in a matter of minuets for testing purposes.

    Leave a comment:


  • tom kroto
    replied
    testing your tutorial locally

    Another dumb question:
    I read your tutorial and all the replies but I still have this question:
    If I can test the .htm locally i.e. by using file>open>browse and finding the .htm on my laptop, why can't I run the CGI you supplied locally too?

    Thanks.

    Leave a comment:


  • Joe Byrne
    replied
    My pleasure Tom!

    I'm actually working on an update, including a section on using SQLite with PBCgi's. I've been fooling around with some advanced scripting and template based concepts too. I'll be posting some news here when their posted and ready to go....

    Leave a comment:


  • tom kroto
    replied
    helpful

    I found your tutorial on CGI. I am just now taking a XHTML/Javascript course so this topic is very interesting to me. Thank you for your efforts here

    Leave a comment:


  • Edwin Knoppert
    replied
    That cookie example on http://www.basicrocks.com/cgi_part3.htm ...

    It says "Cookies are passed to the CGI application in the programs enviroment table...." however..
    The example at first shows how it should be sent, maybe it would be nice to parse the headers sent instead?

    Reason is that IIS is actually parsing the headers and places it in the environment for you.

    I think it would make things slightly more understandable since the headers are often a forgotten thing and spy programs can reveil so much but often are not used.

    I mean, one can really learn from using an MSIE connecting and spying what headers are sent and received.
    It says me more how things work than 'pre-chewed' things like the environment variables (which still needs to be described of course).

    Leave a comment:


  • Mike Stefanik
    replied
    Out of curiousity, I took a look at the project you linked to on CodeProject.com. While free code is nice, and great for learning, I'd never recommend using this (or something like it) for production code unless you're only interested in doing one-off file transfers. Why?

    FTPclient is designed to operate in a stateless mode, in a similar way to how a web request would work. It does not hold open a connection but instead will connect, perform the requested action, and disconnect for each request.
    That is a big ouch right there, and for multiple file transfers imposes an enormous amount of overhead to the application. Not to mention that it could run afoul of security measures on some systems which would see connections like this as a potential denial-of-service attack or probe (and will probably start throttling back connection requests to the application).

    Edit: One other thought while we're on the subject. While using COM Interop to access .NET classes is certainly possible, I doubt that most PowerBASIC developers would really see that as an attractive option. With each method that's invoked, you're looking at somewhere in the neighborhood of an extra 50 or so instructions (quite possibly more, depending on the marshalling involved). Undoubtably there is convenience there, but you pay a significant performance penalty for it. If one really wants to do .NET programming, then use a .NET language. Right tool for the right job, and all that.
    Last edited by Mike Stefanik; 24 Feb 2008, 01:16 PM.

    Leave a comment:


  • Edwin Knoppert
    replied
    Of course you can but frankly, i don't really need ftp at this time.
    The tutorial would be fun to read but should be based on ordinary API examples.

    I was just curious.

    I seen a .NET example, something almost with equal value for me (since .NET is about to be present on all computers.. soon though)

    http://www.codeproject.com/KB/IP/FtpClient.aspx

    Maybe i write me a usefull example with this ever..

    Leave a comment:


  • Joe Byrne
    replied
    As long as we're giving accolades

    I too have SocketTools, but admittedly I haven't used it all that much. The only reason is because I haven't had a real need for it yet. But looking at the library, I can attest to the fact that it is well written and very comprehensive.

    That said, I really can't say enough good things about Marshallsoft's tools. I know they haven't been around these parts in a long time (don't know why, but they do keep the PB code up to date). While FTP can be 'tricky', I've yet to find a server that won't run any of my FTP applications, which are a significant number, using the same commands for all. The $115 US is very well worth every penny to me. I also have their SMTP tools which are invaluable to me as well.

    Again, not to take anything away from SocketTools. When I first needed a good FTP library, SocketTools wasn't around I'm sure however, that their library is just as reliable.

    Leave a comment:


  • Shawn Anderson
    replied
    Edwin,
    I can vouch for the SocketTools library. I have the subscription and it has paid for itself many times over. I've used it to write FTP applications, email applications, and in software to negotiate secure credit card transactions.

    I had a learning curve to get around but Mike provided great support.

    It's good stuff.

    Leave a comment:


  • Mike Stefanik
    replied
    Originally posted by Edwin Knoppert View Post
    Suggestion: FTP ?
    FTP can be a complicated protocol, particularly if you want broad compatibility with a lot of different servers. I know that in SocketTools, we have a lot of code that is dedicated to working around issues with different types of servers. Not all servers support the same command sets, and not all of them have commands that behave in the same way (the STAT command is an example of that). Throw in things like proxies and firewalls into the mix, and you start to get the idea.

    In any case, here's what the code would look like to download a file using SocketTools:

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    #INCLUDE "CSTOOLS5.INC"
    
    FUNCTION PBMAIN () AS LONG
        LOCAL szLocalFile AS ASCIIZ * %MAX_PATH
        LOCAL szRemoteFile AS ASCIIZ * %MAX_PATH
        LOCAL ftpStatus AS FTPTRANSFERSTATUS
        LOCAL bResult AS INTEGER
        
        szLocalFile = "c:\temp\Filename.ext"
        szRemoteFile = "ftp://ftp.example.com/path/filename.ext"
        
        FtpInitialize($CSTOOLS5_LICENSE_KEY, 0)
    
        bResult = FtpDownloadFile(szLocalFile, _        ' Local file path/name
                                  szRemoteFile, _       ' Remote FTP URL
                                  20, _                 ' Timeout in seconds
                                  %FTP_OPTION_PASSIVE, _' Options
                                  ftpStatus, _          ' Transfer status
                                  %NULL, 0)
    
        IF ISTRUE(bResult) THEN
            LOCAL strFileSize AS STRING
            LOCAL strSeconds AS STRING
            
            strFileSize = LTRIM$(STR$(ftpStatus.dwBytesCopied))
            strSeconds = LTRIM$(STR$(ftpStatus.dwTimeElapsed))
    
            MSGBOX "File downloaded successfully (" + _
                   strFileSize + " bytes in " + strSeconds + " seconds)"
        ELSE
            LOCAL dwError AS DWORD
            LOCAL szError AS ASCIIZ * 256
            
            dwError = FtpGetLastError()
            FtpGetErrorString(dwError, szError, 256)
            
            MSGBOX "Error " + HEX$(dwError) + ": " + szError
        END IF
    
        FtpUninitialize()
    
    END FUNCTION
    Pretty straight-forward stuff. There's an FtpUploadFile function as well, so if all you needed to do was simple uploads and downloads, those two functions would cover it. Of course, you can also do more complicated things like list all of the files in a directory on the server, get information about a specific file, send custom site-specific commands and so on.

    Generally speaking, our API has both high-level functions that cover the most common tasks, and lower-level functions for situations where you need customized behavior. For example, some companies actually use FTP as a front-end to a legacy database server, with custom commands used to specify queries, and "download" operations to retrieve the results.

    Leave a comment:


  • Joe Byrne
    replied
    Charles,

    As Shawn pointed out, PB/CGI applications only run on Windows based Web servers. (However, if you have access to a Windows PC/server, you can separate the web pages from the CGI application. The HTML files and CGI programs do not need to run on the same physical machine. You would need a static (fixed) IP address to your windows box, or use a service that routes your dynamic address.....but I may be getting ahead of myself here

    There is a lot you can do with Web apps, but in actuality, they are not all that different than any other PB application. I'm just putting the finishing touches on a rather large reservation system that is made up of 8 web pages (to gather all the necessary data), pulls data from 12 separate Tsunami data files, and in the end updates all 12 (over 25 "writes" not including various reads and numerous calculations and encryptions), then generates a 4-page PDF report with graphics, tables and loads of color, all from one PB/CC program. You just need to get used to the 'back-and-forth' nature of the web.

    Load a page, enter data, run your CGI.
    "" "" "" "" "" "" "" ""
    "" "" "" "" "" "" "" ""
    "" "" "" "" "" "" "" ""
    "" "" "" "" "" "" "" ""

    Of course there are lots of other things you can and usually do to make the process faster. That's where javascript and sometimes PHP/PERL come into play. PHP is fast, lots of pre-written functions floating around, and very portable. But so far, I have yet to find anything done in PHP that I can't do faster and easier (IMO) using PB.

    Leave a comment:


  • Shawn Anderson
    replied
    Charles,
    their server is Linux or Unix so your contact.exe won't run on it..... at least until pbLinux comes out

    Leave a comment:


  • Charles Dietz
    replied
    Joe, I'm trying to learn the cgi technology that you are illustrating in Part 1 of your cgi tutorial. I have web space from Verizon, allocated as part of my contract making them my ISP. After trying to implement your example, I'm getting the following error message:

    The requested method POST is not allowed for the URL /chasdietz/cgi-bin/contact.exe.

    Does that mean what I'm afraid it does... that I cannot use cgi on the web space they've provided?

    My website address is: http://www.cgdsoftware.com

    Thank you for whatever help you have time to give me. I sure do appreciate your cgi tutorial. I have wondered a long time what exactly cgi was.

    Leave a comment:


  • Elias Montoya
    replied
    Great tutorials!!

    Leave a comment:


  • Mike Doty
    replied
    http://www.powerbasic.com/support/pb...ight=pbcgiboth
    Allows using PBWIN with cgi programs.

    Leave a comment:


  • Fred Harris
    replied
    Thanks again, Joe. I was working on it trying to learn the stuff you presented, as well as reviewing a very, very introductory ASP.NET book I have, but...got temporarily sidetracked! Will get back to it soon I hope. I did manage to get the Abyss Web server installed locally (as you recommended) on one of my computers, and was in the process of studying up on those docs. I need to pull it all together.

    Leave a comment:


  • Joe Byrne
    replied
    Part 4 Now Available

    I just posted part 4 of my CGI Programming Primer for those interested.

    Leave a comment:


  • Joe Byrne
    replied
    Suggestion: FTP ?
    You bet! I do a lot of FTP and have used a great many examples and tools from this forum. Don's worked ok for small stuff, but quickly ran out of steam. After much research and testing, I can say without hesitation that the only FTP code I use is: http://www.marshallsoft.com

    Ok, I haven't played with the routines in Socket Tools yet but based on the rest of the package, I'd guess they are pretty good. However, I've yet to be disappointed with any part of Marshallsoft's routines and not being one to remake the wheel, its about as far as I need to go

    Leave a comment:


  • Edwin Knoppert
    replied
    Yes, thanks for the cookie examples, any cookie example you can put up is welcome to me

    In fact anything we usually not see... like all other stuff in the http headers

    Suggestion: FTP ?

    Leave a comment:


  • Bryan Flick
    replied
    Thanks Joe!

    The CGI tutorials are well written and very informative. I don't know squat about Internet programming (but am interested in learning) and I found the tutorials a great place to start.

    Thanks,
    Flick
    www.globalheavyindustries.com

    Leave a comment:

Working...
X