Sending data form a vb program too a mysql DB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James

    #1

    Sending data form a vb program too a mysql DB

    Hello, as this falls under both VB and PHP I have posted this into two
    newsgroups (this is the first time I've done this so if it is mucked up
    then I'm sorry).

    Anyway I want to make some simple games with in VB 6.0 and then I want
    the highscores to go to the server (which uses PHP and MySQL). And if
    its possible I would also like the highscores to be viewable on the
    program AND on my site.

    PHP Part:
    I think I need to set MySQL up so it can be accesssed from outside of
    the server, but I'm not sure.

    Thanks, James.

  • Dag Sunde

    #2
    Re: Sending data form a vb program too a mysql DB

    James wrote:
    Hello, as this falls under both VB and PHP I have posted this into two
    newsgroups (this is the first time I've done this so if it is mucked
    up then I'm sorry).
    >
    Anyway I want to make some simple games with in VB 6.0 and then I want
    the highscores to go to the server (which uses PHP and MySQL). And if
    its possible I would also like the highscores to be viewable on the
    program AND on my site.
    >
    PHP Part:
    I think I need to set MySQL up so it can be accesssed from outside of
    the server, but I'm not sure.
    >
    Are you saying that your VB apps are installed on the users machines,
    but that you want the high-scores to be saved on the mySQL database
    residing on your web-server?

    If so, write a php-script that takes i.e. username and highscore as
    params, and make that phpscript do the db-writing on the server.

    From vb, use the XmlHttp object or one of its siblings to POST
    the data to this php-script on the server.

    To view the high-scores, use the same principle. (Do it from php, and
    when your vb client needs it, Use HTTP).

    --
    Dag.



    Comment

    • Steve Gerrard

      #3
      Re: Sending data form a vb program too a mysql DB


      "Dag Sunde" <me@dagsunde.co mwrote in message
      news:4559e5e9$0 $16511$8404b019 @news.wineasy.s e...
      >
      From vb, use the XmlHttp object or one of its siblings to POST
      the data to this php-script on the server.
      >
      To view the high-scores, use the same principle. (Do it from php, and
      when your vb client needs it, Use HTTP).
      >
      Dag, how much data is reasonable to move back and forth using the XmlHttp object
      in VB6? Is it pretty much limited to a few parameters like name, rank, and
      serial number, or can you move a list of stuff? It sounds just right for OP's
      needs, but I'm curious about other situations. I suppose I could try moving more
      data with a series of calls or something?



      Comment

      • Dag Sunde

        #4
        Re: Sending data form a vb program too a mysql DB

        Steve Gerrard wrote:
        "Dag Sunde" <me@dagsunde.co mwrote in message
        news:4559e5e9$0 $16511$8404b019 @news.wineasy.s e...
        >>
        >From vb, use the XmlHttp object or one of its siblings to POST
        >the data to this php-script on the server.
        >>
        >To view the high-scores, use the same principle. (Do it from php, and
        >when your vb client needs it, Use HTTP).
        >>
        >
        Dag, how much data is reasonable to move back and forth using the
        XmlHttp object in VB6? Is it pretty much limited to a few parameters
        like name, rank, and serial number, or can you move a list of stuff?
        It sounds just right for OP's needs, but I'm curious about other
        situations. I suppose I could try moving more data with a series of
        calls or something?
        If you use the "GET", it is limited to the max-length of the URL...

        In Internet Explorer, this is 2,083 bytes, so I guess it is something
        similar in the XMLHttp-object too.

        If you use "POST" on the other hand, it is up to the server.
        In IIS, the maximum number of bytes for one form variable is
        approx. 102,399 bytes. To overcome this, you just send
        several fields (variables) with the same name. IIS (ASP)
        will then see them as an array you can loop thru.

        I frequently send (POST) 500K via the xmlhttp object to an
        ASP script running on IIS 5.0...

        So if my POST'ed data look like this:
        //PseudoJavascrip t
        sData = "xmlData=" + escape("102399B ytesOfData")
        sData = sData + "&xmlData=" + escape("another 102399BytesOfDa ta")

        xmlReq.open("PO ST", "Receiver.a sp", true);
        xmlReq.onreadys tatechange = xmlSendBidCallb ack;
        xmlReq.setReque stHeader( "Content-Type",
        "applicatio n/x-www-form-urlencoded");
        xmlReq.send( sData );

        My Receiver.asp will assemble it like this:

        //VBS fragment..
        Dim xmlData
        Dim i
        for i = 1 to Request.Form("X mlData").Count
        xmlData = xmlData & Request.Form("X mlData")(i)
        next

        --
        Dag.



        Comment

        • James54321

          #5
          Re: Sending data form a vb program too a mysql DB

          Um, wouldnt doing it like that give a major vulnerability so users can
          cheat by going to http://mysite.com/highscores.php?score=23&name=me or
          is that not how you meant :S.

          Thanks, James.

          Comment

          • Dag Sunde

            #6
            Re: Sending data form a vb program too a mysql DB

            Dag Sunde wrote:
            Steve Gerrard wrote:
            >"Dag Sunde" <me@dagsunde.co mwrote in message
            >news:4559e5e9$ 0$16511$8404b01 9@news.wineasy. se...
            >>>
            >>From vb, use the XmlHttp object or one of its siblings to POST
            >>the data to this php-script on the server.
            >>>
            >>To view the high-scores, use the same principle. (Do it from php,
            >>and when your vb client needs it, Use HTTP).
            >>>
            >>
            >Dag, how much data is reasonable to move back and forth using the
            >XmlHttp object in VB6? Is it pretty much limited to a few parameters
            >like name, rank, and serial number, or can you move a list of stuff?
            >It sounds just right for OP's needs, but I'm curious about other
            >situations. I suppose I could try moving more data with a series of
            >calls or something?
            >
            If you use the "GET", it is limited to the max-length of the URL...
            >
            In Internet Explorer, this is 2,083 bytes, so I guess it is something
            similar in the XMLHttp-object too.
            >
            If you use "POST" on the other hand, it is up to the server.
            In IIS, the maximum number of bytes for one form variable is
            approx. 102,399 bytes. To overcome this, you just send
            several fields (variables) with the same name. IIS (ASP)
            will then see them as an array you can loop thru.
            >
            I frequently send (POST) 500K via the xmlhttp object to an
            ASP script running on IIS 5.0...
            >
            So if my POST'ed data look like this:
            //PseudoJavascrip t
            sData = "xmlData=" + escape("102399B ytesOfData")
            sData = sData + "&xmlData=" + escape("another 102399BytesOfDa ta")
            >
            xmlReq.open("PO ST", "Receiver.a sp", true);
            xmlReq.onreadys tatechange = xmlSendBidCallb ack;
            xmlReq.setReque stHeader( "Content-Type",
            "applicatio n/x-www-form-urlencoded");
            xmlReq.send( sData );
            >
            My Receiver.asp will assemble it like this:
            >
            //VBS fragment..
            Dim xmlData
            Dim i
            for i = 1 to Request.Form("X mlData").Count
            xmlData = xmlData & Request.Form("X mlData")(i)
            next
            Forgot!

            The response from these calls has no limit in its response...
            (Except for timeout issues...)

            So if you send a short request like "getHiscores.as p?limit=all",
            and that results in a .responseText being 900K lonk, that
            is not a problem, and no special consideration needs to be made.

            --
            Dag.


            Comment

            • Dag Sunde

              #7
              Re: Sending data form a vb program too a mysql DB

              James54321 wrote:
              Um, wouldnt doing it like that give a major vulnerability so users can
              cheat by going to http://mysite.com/highscores.php?score=23&name=me or
              is that not how you meant :S.
              >
              That can be avoided by letting the VB-App log in to the web-app first,
              using the same principle and with a buildt-in MD5 or SHA1 encrypted
              password first. Let the login return a sessionID, and then use that
              id as a parameter in all subsequent calls.

              --
              Dag.



              Comment

              • James54321

                #8
                Re: Sending data form a vb program too a mysql DB


                Dag Sunde wrote:
                James54321 wrote:
                Um, wouldnt doing it like that give a major vulnerability so users can
                cheat by going to http://mysite.com/highscores.php?score=23&name=me or
                is that not how you meant :S.
                >
                That can be avoided by letting the VB-App log in to the web-app first,
                using the same principle and with a buildt-in MD5 or SHA1 encrypted
                password first. Let the login return a sessionID, and then use that
                id as a parameter in all subsequent calls.
                >
                --
                Dag.
                Won't doing that mean that I have to use the browser in VB or IE or
                something like that meaning that the user will see whats going on?

                Comment

                • Dag Sunde

                  #9
                  Re: Sending data form a vb program too a mysql DB

                  James54321 wrote:
                  Dag Sunde wrote:
                  >
                  >James54321 wrote:
                  >>Um, wouldnt doing it like that give a major vulnerability so users
                  >>can cheat by going to
                  >>http://mysite.com/highscores.php?score=23&name=me or is that not
                  >>how you meant :S.
                  >>>
                  >>
                  >That can be avoided by letting the VB-App log in to the web-app
                  >first, using the same principle and with a buildt-in MD5 or SHA1
                  >encrypted password first. Let the login return a sessionID, and then
                  >use that id as a parameter in all subsequent calls.
                  >>
                  >--
                  >Dag.
                  >
                  Won't doing that mean that I have to use the browser in VB or IE or
                  something like that meaning that the user will see whats going on?
                  Nope...
                  :-)

                  Add "Microsoft XML, v3.0" (or higher) to references in a vb project.

                  Put a textbox and a command buttom on the form,
                  and set the textbox multiline property to true
                  and make it about an inch high.

                  Paste this code:

                  Option Explicit

                  Private xmlHttp As MSXML2.xmlHttp

                  Private Sub Command1_Click( )

                  Set xmlHttp = New MSXML2.xmlHttp
                  xmlHttp.Open "POST", "http://dagsunde.com/pages/Reverse.asp", False
                  xmlHttp.SetRequ estHeader "Content-Type",
                  "applicatio n/x-www-form-urlencoded"
                  xmlHttp.Send "testString =" & Text1.Text

                  If xmlHttp.readySt ate = 4 Then
                  If xmlHttp.Status = "200" Then
                  Text1.Text = xmlHttp.respons eXML.xml
                  Else
                  MsgBox "Something went wrong...", vbCritical, "ResponseXM L
                  error"
                  End If
                  End If

                  End Sub


                  And run...
                  (My server will respond, and if you don't use a http-sniffer
                  or some other tool, you will not see whats going over the line).

                  --
                  Dag.


                  Comment

                  • Steve Gerrard

                    #10
                    Re: Sending data form a vb program too a mysql DB


                    "Dag Sunde" <me@dagsunde.co mwrote in message
                    news:4559fab0$0 $16502$8404b019 @news.wineasy.s e...
                    Dag Sunde wrote:
                    >Steve Gerrard wrote:
                    >>Dag, how much data is reasonable to move back and forth using the
                    >>XmlHttp object in VB6?
                    >>
                    >If you use the "GET", it is limited to the max-length of the URL...
                    >>
                    >If you use "POST" on the other hand, it is up to the server.
                    >In IIS, the maximum number of bytes for one form variable is
                    >approx. 102,399 bytes. To overcome this, you just send
                    >several fields (variables) with the same name. IIS (ASP)
                    >will then see them as an array you can loop thru.
                    >>
                    >I frequently send (POST) 500K via the xmlhttp object to an
                    >ASP script running on IIS 5.0...
                    >>
                    >So if my POST'ed data look like this:
                    > //PseudoJavascrip t
                    >sData = "xmlData=" + escape("102399B ytesOfData")
                    >sData = sData + "&xmlData=" + escape("another 102399BytesOfDa ta")
                    >>
                    The response from these calls has no limit in its response...
                    (Except for timeout issues...)
                    >
                    So if you send a short request like "getHiscores.as p?limit=all",
                    and that results in a .responseText being 900K lonk, that
                    is not a problem, and no special consideration needs to be made.
                    >
                    Ooh, I like it, 100K seems like decent amount to be able to post, and it looks
                    like sending multiple blocks is not much more work. I have been ducking away
                    from doing some of this, but the time is rapidly approaching. Thanks for the
                    answers and the examples and the "oh it is really no trouble at all" breezy
                    attitude. I'm sure there will be a little swearing along the way, but I feel
                    much more confident about making it work.

                    From the example in your other post:
                    <?xml version="1.0"?>
                    <root>
                    <rev_string>.uo yknahT</rev_string>
                    </root>


                    Comment

                    • Dag Sunde

                      #11
                      Re: Sending data form a vb program too a mysql DB

                      Steve Gerrard wrote:
                      "Dag Sunde" <me@dagsunde.co mwrote in message
                      news:4559fab0$0 $16502$8404b019 @news.wineasy.s e...
                      <snipped/>
                      >>
                      >So if you send a short request like "getHiscores.as p?limit=all",
                      >and that results in a .responseText being 900K lonk, that
                      >is not a problem, and no special consideration needs to be made.
                      >>
                      >
                      Ooh, I like it, 100K seems like decent amount to be able to post, and
                      it looks like sending multiple blocks is not much more work. I have
                      been ducking away from doing some of this, but the time is rapidly
                      approaching. Thanks for the answers and the examples and the "oh it
                      is really no trouble at all" breezy attitude. I'm sure there will be
                      a little swearing along the way, but I feel much more confident about
                      making it work.
                      From the example in your other post:
                      <?xml version="1.0"?>
                      <root>
                      <rev_string>.uo yknahT</rev_string>
                      </root>
                      LOL

                      If you get into trouble, swear in my direction, and I'll try
                      to help you out...


                      That reminds me... Here is the Reverse.asp script:

                      <%@ Language=VBScri pt %>
                      <%Response.Buff er = True%>
                      <%
                      Response.Conten tType = "text/xml"
                      Response.CacheC ontrol = "Private"
                      Response.AddHea der "Cache-Control", "no-cache"

                      Dim testString
                      testString = Request.Form("t estString")
                      testString = StrReverse(test String)

                      Response.Write( "<?xml version='1.0' encoding='iso-8859-1'?>" )
                      Response.Write( "<root>" & vbCrLf)
                      Response.Write( "<rev_strin g>" & testString & "</rev_string>" & vbCrLf )
                      Response.Write( "</root>" & vbCrLf)
                      Response.End()
                      %>

                      The reason for setting the contenttype to "text/xml" is to tell the
                      xmlhttp object that it will get xml-data back, and that it should
                      be able to fill its .responeXml attribute with a DOM tree.
                      Note that you then have to .Write well-formed xml back to it.

                      I often use plaintext instead:
                      Response.Write( testString )
                      Response.End()

                      In this case, the .responseXML will be empty (no valid xml),
                      but use the .responseText instead (on the client side).

                      --
                      Dag.


                      Comment

                      Working...