#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    4
    Rep Power
    0

    Lightbulb curl and a certificate.pem


    I'm using the following code to get the output of a https site.

    That site also needs an ssl certificate: tpa1266.pem.

    I have the certificate in the same directory that I'm running the php script.

    When I execute the PHP script I get the error: "unable to set certificate file (wrong password?)"

    My certificate doesn't have a password. I created the certificate using the options -nodes.

    If I go to a DOS prompt and I type
    curl -v -o output.txt -E tpa1266.pem http:// ......

    It works!!

    So,

    any ideia of what's wrong in my PHP code ???


    <?php

    $url = "https://cer.pnet.multibanco.pt/pvtn?A030=M001&A001=1266&C007=&C013=&A061=&A105=9782&B1=Submit/";


    $cert = "tpa1266.pem";
    $ch = curl_init ($url);
    $fp = fopen ("output.txt", "w");

    curl_setopt ($ch, CURLOPT_SSLCERT, $cert);
    curl_setopt ($ch, CURLOPT_SSLCERTPASSWD, "");
    curl_setopt ($ch, CURLOPT_FILE, $fp);
    curl_setopt ($ch, CURLOPT_HEADER, 0);

    curl_exec ($ch);

    // Error handling
    echo curl_error($ch);

    curl_close ($ch);
    fclose ($fp);
    ?>
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    4
    Rep Power
    0
    The problem was here:

    $cert = "tpa1266.pem";

    We need to include the whole path to the file, for example:

    $cert = "/tmp/cert.pem"

    So easy!

IMN logo majestic logo threadwatch logo seochat tools logo