Using Network functions with PHP

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andre.

Hello PB friends !

Got another code for testing from a german user. And as I haven't any knowledge about network programming I will post the code here.
He tried all snippets he could find on the forums etc.... :)

He was able to program the needed functions with WinAPI, but he want to code them with PB functions for cross-plattform etc.

The code was tested on Win98, Win98 Second Edition, ME, W2K and XP, so it shouldn't be an OS related problem.

Could you please test the code? Either its a programming fault or a possible bug...

(Notes: The URL was established extra for testing. The using of the PHP scripts is strongly needed, because most ISP's doesn't allow the access with ODBC to the MySQL.)

Here comes the used PB code:

Code: Select all

Global eol$

eol$ = Chr(13) + Chr(10)
*Buffer = AllocateMemory(0,10000,0)

If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 320, 240, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered, "INet-Highscore")
  ConnectionID= OpenNetworkConnection("[url]http://www.mduttlinger.de[/url]", 80) 
  If ConnectionID
    msg$ = "GET [url]http://www.mduttlinger.de/hs2/newscore.php?hein&510&a&b&c&d&e&f&5555[/url]  HTTP/1.1" + eol$
    ;SendNetworkString(ConnectionID, msg$)
    ;SendNetworkString(ConnectionID, eol$)
    PokeS(*Buffer, msg$)
    SendNetworkData(ConnectionID, *Buffer, Len(msg$)) 
    PokeS(*Buffer, eol$)
    SendNetworkData(ConnectionID, *Buffer, Len(eol$))
    CloseNetworkConnection(ConnectionID)
  Else
    MessageRequester("Error", "Can't create theconnection !", 0)
  EndIf
  
  Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until quit = 1
EndIf
FreeMemory(0)
End
And here the relating PHP script:

Code: Select all


Regards
André

*** German PureBasic Support ***
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

You need 2 more blank line to finish the header AFAIK:

SendNetworkData(ConnectionID, *Buffer, Len(eol$))
SendNetworkData(ConnectionID, *Buffer, Len(eol$))

And I don't think than this header is enough for most web servers.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

The standar header is

Code: Select all

      webpage$ = "[url]http://www.site.com/index.php?bla=bla[/url]"
      header$="GET "+webpage$+" HTTP/1.1"+Chr(13)+Chr(10)
      header$=header$+"Accept: */*"+Chr(13)+Chr(10)
      header$=header$+"Accept: text/html"+Chr(13)+Chr(10)
      header$=header$+"Host: "+host$+Chr(13)+Chr(10)
      header$=header$+"User-Agent: HTTP-For-PureBasic"+Chr(13)+Chr(10)
      header$=header$+Chr(13)+Chr(10)

ConnectionID.l= OpenNetworkConnection("[url]http://www.site.com[/url]",80)
      
      If ConnectionID
      SendNetworkData(ConnectionID,@header$,Len(header$))
      ...
I work many times with PHP called from PB and for PB there is no difference... i mean that its just like static pages. Just send the data in the url (index.php?myvar=xx) and parse the resulting html page.
Yes, its the best way to use MySQL from a server. I manage sometimes a laaarge database in a server using PB in this way with no problems.


Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dutti.

Hi there,
i was the user that send this code to Andrè.
Thanks to Fred and Ricardo for posting. I have tried
the Header that Ricardo has posted and it works fine.

best regards

dutti
Post Reply