[web] PHP Session

Started by
5 comments, last by tstrimp 17 years, 7 months ago
Hi, Does anybody have any ideas about what i want to do? I want my php script to connect to a site, parse the html result and output some specific info to the browser. I did this before with success. But now i want to do the same with a site that has been secured via PHP Session. I think i need to post my login information to the site and handle some incoming cookies or something (???) I used sessions before on my own sites, but i don't really know how they work on the client side. I want to automate some functionality of a 3rd party site (don't worry not gamedev :) ). I have a gift certificate application that needs to send a message to a recipient via the secured site containing the link to the certificate. Thanks & Greetings, Eddy
Advertisement
You need to be able to handle session cookies on your end. That's how PHP usually tracks sessions. Unfortunately I have no idea how to do the client side in PHP.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

You will need to use CURL for this, as it can handle post data. CURL also handles cookies.

$tempFile = '/tmp/cookiejar.txt';$url = 'http://www.example.com';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_COOKIEJAR, $tempFile);curl_setopt($ch, CURLOPT_COOKIEFILE, $tempFile);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$content = curl_exec ($ch);


If you keep the same filename across multiple requests then you should be fine.
You don't NEED to use Curl, in fact PHP has a built-in HTTP implementation. But it has no (specific) support for cookies, you'd have to write your own.

Mark
Ok cool. Curl sounds fine i guess, i'll give that a try. If it doesn't turn out to work for me i'll just write my own cookie handler.

@Markr: any reason not to use curl? I don't feel like reinventing the wheel, unless i can make it better.

Greetings.
Quote:Original post by markr
You don't NEED to use Curl, in fact PHP has a built-in HTTP implementation. But it has no (specific) support for cookies, you'd have to write your own.


My mistake. I've only ever used CURL.
Quote:Original post by kwackers
Quote:Original post by markr
You don't NEED to use Curl, in fact PHP has a built-in HTTP implementation. But it has no (specific) support for cookies, you'd have to write your own.


My mistake. I've only ever used CURL.


There is no reason not to use CURL. It has much more functionality then the PHP HTTP implimentation. CURL FTW!

This topic is closed to new replies.

Advertisement