Hi guys,

I need some help. I have a URL I need to open, lets call it http://url.com/page.php from a PHP script on a different server... Sounds easy, just use fopen fread or something... But then it gets a little more trickly. I have a cookie on my computer which http://url.com/page.php uses, but would it sill use itif it was called by this other page, and if not, how can I get around that issue? The other thing is, I need this page to pretend thathttp://url.com/page.php's referrer is http://click.com/redirect.php say... How can I do this?

Thanks!

    I would guess the answer is no since cookies are client side, and the call is being made server-side...You would have to store your cookie information in a database or a duplicate of it on the server...kind of a weird hack though...but to my knowledge, I'm pretty sure a server to server call can't read a cookie on some other client machine.

      Never thought of that. The cookie will always have the same variables with the same values so if I just set them variables and values at the top of the page that'll work when I use fopen? Hmmm... Ok, any idea on the referrer bit?

        Hang on... It's the server calling the URL so perhaps what I actually need to do is move this cookie I have over to the server? Where abouts on the server do you reckon I'd need to put it for the page to recognize it when I call it?...Thanks!!

          Have you investigated using sessions?

            You may need to get your hands dirty here. Instead of using fopen, you may need to go down to the raw connection.

            If I recall correctly, you can set cookie values when you request a page using curl. Any cookies which the remote server wants to set are detailed in the headers of the returned page.

            So you need to look into the curl functions (http://ie2.php.net/manual/en/ref.curl.php). Then you can store any incoming cookies and send out any required cookies when your server contacts the remote server.

              Good Idea...

              here is an implementation of CURL I've used before...note, the parameters you pass are in an array and can be accessed as post vars on the page you call....

                 $params = array(); //Possibly filled by your cookie values
              
                 $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
              
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_POST,1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
                 curl_setopt($ch, CURLOPT_URL,$url);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
                 curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  // this line makes it work under https
              
                 $result=curl_exec($ch);
                 curl_close ($ch);
              

                basic http request with cookies and referers is

                GET /thepage.php HTTP/1.0\r\n
                Host: www.host.com\r\n
                Referer: http://www.site.com/page.php\r\n
                Cookie: key1=val1; key2=val2; key3=val3;\r\n
                User-Agent: whatever\r\n
                Connection: close\r\n\r\n

                you can use that with [man]fsockopen[/man] or try curl like posted above.

                  Write a Reply...