Change post form data function into curl

Posted by QLiu on Stack Overflow See other posts from Stack Overflow or by QLiu
Published on 2010-04-22T09:59:14Z Indexed on 2010/04/23 21:53 UTC
Read the original article Hit count: 147

Filed under:

Hello Guys,

In the old way in our website, when users clicks “logout” button. It runs a post form function; which will pass parameters (logout, sn) to external sites to execute “logout” function. Like:

I do not want the users jump to the external site, therefore, i use curl to post data. (because we are in different domain, i guess Ajax request doesnot work )

Post the same data to execute logout function in external site.

// create cURL resource
        $URL = "http://bswi.development.intra.local/";

        //Initl curl
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $URL);  // Load in the destination URL
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Normal HTTP request, not SSL
        curl_setopt($ch, CURLOPT_POSTFIELDS, "logout=1"); 

       // receive server response ...
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_exec ($ch);
        echo $content;
        curl_close ($ch);

Do u think i am going in the right direction?

© Stack Overflow or respective owner

Related posts about curl