I'd HIGHLY recommend using curl for this. Curl, with a flip of a switch, can handle saving and sending cookies without much effort on your part.
Otherwise, I think you can still do it using fsockopen(), but you'd have to work code in there to grab the headers which is where the cookies are at, save the cookies, and then manage sending the headers back with the cookies. Probably not too difficult, but curl makes it a lot easier.