Using PHP sessions with BlitzMax

BlitzMax Forums/BlitzMax Beginners Area/Using PHP sessions with BlitzMax

Leon Brown(Posted 2007) [#1]
Does anyone know how to make use of PHP sessions with BlitzMax? I have a function that uses ConnectSocket() to send information to the server, so would assume that there is a parameter in the header that I can use to store the session ID that was returned from the server during a previous information call.

Headers that I'm currently sending include:

Host: "+host)
Content-type: application/x-www-form-urlencoded
User-agent: MyApp
Content-length: 100
Pragma: no-cache
Connection: keep-alive


Header settings that are being returned from the sign in call to the PHP script:

HTTP/1.1 200 OK
Date: Sat, 18 Aug 2007 20:07:57 GMT
Server: Apache/1.3.33 (Darwin) PHP/4.4.1
X-Powered-By: PHP/4.4.1
Set-Cookie: PHPSESSID=bf466c8240e4beabe8f18f46d8a49b56; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Content-Type: text/html



SebHoll(Posted 2007) [#2]
Although I'm not entirely sure, I believe Brucey's latest libcurl module should make BlitzMax internet communication a lot easier. Try downloading it - I think it should allow you to make requests for web pages (including PHP) without having to manually code all the header handling yourself for the HTTP stream youself.


Brucey(Posted 2007) [#3]
Yep, libcurl can handle cookies and things for you, if you want it to.
One of the included examples shows how to get and view cookies retrieved from google. The included documentation also touches on the subject of handling cookies.

A link to the standard libcurl module.

A link to the SSL-enabled libcurl module.


Of course, you can always work it out yourself. (A session is just a cookie with an id that you need to pass back and forth in order to let the server know that you are the same person as before.)
...whichever suits :-)


FlameDuck(Posted 2007) [#4]
Just add:
Cookie: PHPSESSID=bf466c8240e4beabe8f18f46d8a49b56
back. Or do what Brucey said.


Leon Brown(Posted 2007) [#5]
Thanks guys. Brucey's work sounds promising and I will look at it the next time I need to transfer information from my app to the server, but because I have the code pretty much working, it may be quicker to find out what information mation needs to be in the heading, as I wouldn't have to worry about installing anything or writing new code.

I tried using Cookie: PHPSESSID=bf466c8240e4beabe8f18f46d8a49b56 , but that didn't work either. I've also used Session-Id: , but that doesn't work.


FlameDuck(Posted 2007) [#6]
I tried using Cookie: PHPSESSID=bf466c8240e4beabe8f18f46d8a49b56 , but that didn't work either.
You have to return the same ID (hash) as you get from the server. It does work. It's how your browser does it. You can look through your browser cache for the specific cookie. It'll be named something like PHPSESSID@.... Also, if using Firefox, install the LiveHTTPheaders plug in, and you can see exactly what's going on, and perhaps more importantly, what's not going on.


Leon Brown(Posted 2007) [#7]
Thanks for you help FlameDuck. I checked the cookies in my browser and it would make sense, but BlitzMax doesn't seem to be activating the session cookie when I write it. I used the LiveHTTPheaders plug in to copy all of the header information from when I sign into the web app from my HTML interface, but BlitzMax still doesn't sign in.

The better way to solve the problem will probably be for me to write a custom interface in PHP that will collect the information required by BlitzMax.

Thanks for all your help, it's certainly been handy to find out how to see all of the header information being sent to and from the server.