(1) You have to read the headers, and fopen the other URL instead.
(2) You will have to construct a header that has the cookie stuff you want, and send it to the server. How to do this with fopen() is beyond me, and probably beyond doing. You are probably going to have to change to sockets so you have a 2-way communication with the server, and issue the GET directly rather than letting the fopen() interface do it for you.