Foxpro Webesite Log in

Posted on 2012-09-02
Last Modified: 2012-09-11
I have a VFP 8.0 program which needs to automatially log into a website by providing my login name and password.   This is necessary to access certain member only areas which my subscription allows me to see, but not casual users.

It appears that each page looks to see if the user is logged in before presenting the actual data page.  I wonder if this is done with a cookie which needs to be created before actually navigating to the page.  

I am currently using ic=CREATEOBJECT("inetctls.inet") to get a connection to the page(s) using

The page opens, but checks something to see if I'm logged in , does not find it and presents an option to login without showing the content of the actual page.

On normal pages, I use STRTOFILE(pagecontents, "e:\THISdata.htm") and then open the file for parsing using   infile=FOPEN("e:\THISdata.htm")

STRTOFILE(pagecontents, "e:\THISdata.htm")
thisline = fgets(infile)
   ....... test if required data in this line
   ....... continue to read in thisline=fgets(infile)
until eof(infile)

This sequence works fine, if the page does not need the user to be looged in.

BTW, I AM a paid subscriber to this website, so I'm not trying to get data which I am not supposed to see.

Please include working code if answering this question, generic answers will not be considered.

Thanks for your help.
Question by:wheat01
    LVL 27

    Assisted Solution

    You asked for sample code.

    This is what I do to fill forms when calling them from VFP:

    PUBLIC ie AS InternetExplorer.Application
    cString = ''
    cString = cString + '<html>'
    cString = cString + '<body>'
    cString = cString + '<form name="form1">'
    cString = cString + '<input type="text" id="name" value="">'
    cString = cString + '</form>'
    cString = cString + '</body>'
    cString = cString + '</html>'
    = STRTOFILE(cString,'html.htm')
    ie = CREATEOBJECT("InternetExplorer.Application")
    ie.Visible = .T.
    ie.Navigate2(ADDBS(SYS(5)+SYS(2003))+'html.htm') = 'Cyril'

    Open in new window

    You need to turn off the security in Internet Explorer for this to work properly. Of course you can use other means to access the website like HTTP Request or use a WebBrowser control inside a VFP form which is the easiest of all.
    LVL 29

    Assisted Solution

    by:Olaf Doschke
    There is one simple solution without changing your code. Login before you use your code, and your user session should be valid. That works for me, when using Internetexplorer.Application or msxml2.xmlhttp

    If the login is using BasicAuth, the inetctls.inet Ole class you use has Password and Username properties you can set.

    If not you can use Cyrils = 'user' and ie.document.form1.password.value = 'password' before submitting the login form. You just need to know the login page, login form name and input tag names to automate them this way.

    There's no way to tell from your question, what authentication method is used by the website. BasicAuth is typically determined by being able to add to the request url and in behaviour will create a popup login window, but that's not a sure sign it's BasicAuth.

    No matter what login mode, once you're logged in and your session is valid normal requests will work. There fore again the non code just general answer: Login before using your application, then you don't have to fiddle and find out what code to add for automaitc login.

    Bye, Olaf.
    LVL 27

    Expert Comment

    Once you login no matter how, you need to keep that session alive otherwise the server will think you are another user in different requests.

    1) Keep WebBrowser or InternetExplorer open.
    2) Keep the handle global and make subsequent calls from same handle.
    LVL 29

    Expert Comment

    by:Olaf Doschke
    Cyril, if a session cookie is not deleted because you close the browser depends on your browser settings. If you don't set the option to delete cookies with shutdown of the app, but keep cookies according to their expiration date/time. For a starter it should be ok to keep the IE browser open. It doesn't work at all, if using another browser. The OLE infrastructure of inetctls.inet, msxml2.xmlhttp or internetexplorer.application is only seeing ie sessions. Not only cookie based sessions. Basic auth, for example,  is not cookie based, but is not used with typical community website logins anyway.

    @wheat01: More info is needed for more concrete code.

    I just can add one more general hint: If the website supports developer add ons and offers web services or any other API you should look into that. Google, Yahoo, Twitter and many more offer oAuth authentication. I have provided a little oAuth lib here:

    Bye, Olaf.

    Accepted Solution


    Thanks for the direction.  I finally "solved" the issue with the code below.  Not as elegant but it works every time without user intervention.


    do while oInet.busy
        wait "busy" window nowait timeout 1
    oInet.visible = .t.
    LVL 29

    Expert Comment

    by:Olaf Doschke
    Fair enough.

    You could get concrete code, if you'd simply tell us, into what site you want to log in. Login forms and specifics can be very different from site to site. There are standards like BasicAuth, working with .htaccess, but no community site uses that, this is just basic directory accesss protection.

    As you use inetctls.inet, that points towards FTP, but you don't make FTP requests.

    some logins base on session cookies, some demand that, some have a fallback of storing session data in a backend database.

    Typically you submit a html form like the user would do manually. Some sites as gmail actually hinder automatic html form submit, so I can't guarantee I'd be able to give you code. In thqat case you could use OAuth, actually.

    If html form automation would work, it would most probably be along the lines of what Cyril already gave you: You fill in user and password into the DOM of a browser and call the form submit. There are more elegant ways to submit a html form than by sendkeys. you can do document.getElementById("loginform").submit();

    Again:  Login forms and specifics can be very different from site to site, not only names of the html form elements may differ, they may be captchas to hinder automation.

    Bye, Olaf.

    Author Closing Comment

    Solution is the specific code required to provide the connection to the site with correct login and password which then makes the site content avaialble.

     However, I did award the points between the two experts for giving me some direction in solving the problem.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: (http://msd…
    In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now