• Advertisement
Sign in to follow this  

[web] PHP Session

This topic is 4184 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
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

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
Sign in to follow this  

  • Advertisement