0

I need some help in this.

I'm trying to make a $_POST into an external webpage's form. The idea is the next:

  • the user enters to my webpage. www.caae.cl/encuesta
  • the user enters a username and password (into my webpage)
  • I submit into the external webpage's form (https://www.uc.cl), which i dont have control, the user and pw
  • i check if the combination is correct
  • i redirect the user into my webpages user's homepage

I have two points: first of all how do i make the submit through cUrl and the second one, I need to read the cookie of the external webpage to check if the user-password combo is ok

i would appreciate any help. Im working with php and curl.

Dan Stern
  • 2,155
  • 8
  • 26
  • 38

1 Answers1

2

Read the documentation for cURL here. It has options you can use for POST data, cookies, and HTTPS.

But, to help you out, here is a function I use to make cURL requests. You'll want to modify the options for your own purposes, e.g. you want to enable the HTTPs options, and you may not want to store cookies. Read the documentation though!

function curl_request($url, $referer = false, $postdata = false, $new_session = false) //single custom cURL request.
{
    $ch = curl_init();
    if ($new_session)
    {
        curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    }
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     

    curl_setopt($ch, CURLOPT_URL, $url);

    if ($referer)
    {
        curl_setopt($ch, CURLOPT_REFERER, $referer); 
    }

    if ($postdata)
    {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);   
    }

    $response = curl_exec($ch);

    curl_close($ch);

    return $response;
}

Also, if it's necessary to get the cookie vars into a php variable, follow the answer here. Think carefully about whether checking the cookie is the best way to check login though.

Community
  • 1
  • 1
Ben G
  • 26,091
  • 34
  • 103
  • 170