Sign in to follow this  
Limitz

[web] PHP Session

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this