A PHP Error was encountered

Severity: Notice

Message: Undefined index: HTTP_ACCEPT_LANGUAGE

Filename: core/MY_Controller.php

Line Number: 258

Backtrace:

File: /home/lourenss/www/pingen_www/application/core/MY_Controller.php
Line: 258
Function: _error_handler

File: /home/lourenss/www/pingen_www/application/core/MY_Controller.php
Line: 54
Function: get_browser_language

File: /home/lourenss/www/pingen_www/application/controllers/Api.php
Line: 7
Function: __construct

File: /home/lourenss/www/pingen_www/index.php
Line: 316
Function: require_once

Pingen | Send Letters Online for Private, Business and Software Developers

Official PHP-Class for pingen.com

We provide a read-to-go PHP-Library for using pingen.com.
Check it out here

Manual example

Upload and send a PDF priority and in color.

    $sToken = ''; //Add your private token here
    $sFile = realpath('/path/to/your/file.pdf');

    //set URL
    $sURL = 'https://api.pingen.com/document/upload/token/' . $sToken;

    //build our query data
    $aData = array(
        'data' => json_encode(array(
            'send' => true, //we want to automatically send it
            'speed' => 1, //we want to send priority
            'color' => 1, //and in color
        )),
        'file' => '@' . $sFile
    );

    //set the url, number of POST vars, POST data
    $objCurlConn = curl_init();
    curl_setopt($objCurlConn,CURLOPT_URL,$sURL);
    curl_setopt($objCurlConn,CURLOPT_POST,1);
    curl_setopt($objCurlConn,CURLOPT_POSTFIELDS,$aData);
    curl_setopt($objCurlConn, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($objCurlConn, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($objCurlConn, CURLOPT_SSL_VERIFYPEER, 0);

    //execute post
    $sResult = curl_exec($objCurlConn);

    // decode result and pass from here on
    $aResult = json_decode($sResult, true);

    if ($aResult['error']==true)
    {
        //an error occured, handle it from here
    }else {
        //go along with your code here
    }

If for some reason you can not use CURL (we highly recommend it) you can also directly use PHP Sockets to make the POST-Request

    function pingen_upload($host, $port, $path, $postdata = array(), $filedata = array()) {
        $data = "";
        $boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
        $fp = fsockopen("ssl://" . $host, $port);

        fputs($fp, "POST $path HTTP/1.0\n");
        fputs($fp, "Host: $host\n");
        fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n");

        // Put together variable data
        foreach($postdata as $key => $val){
            $data .= "--$boundary\n";
            $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n";
        }

        // Put together file data
        if($filedata) {
            $data .= "--$boundary\n";
            $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n";
            $data .= "Content-Type: ".$filedata['type']."\n";
            $data .= "Content-Transfer-Encoding: binary\n\n";
            $data .= $filedata['data']."\n";
            $data .= "--$boundary--\n";
        }

        // Senden aller Informationen
        fputs($fp, "Content-length: ".strlen($data)."\n\n");
        fputs($fp, $data);

        $res = '';
        // Read return
        while(!feof($fp)) {
            $res .= fread($fp, 1);
        }
        fclose($fp);

        return $res;
    }

    $sToken = ''; //Add your private token here
    $sFile = realpath('/path/to/your/file.pdf');

    //build our query data
    $aData = array(
        'send' => true, //we want to automatically send it
        'speed' => 1, //we want to send priority
        'color' => 1, //and in color
    );

    $aPostData = array('data'=>json_encode($aData));
    $aFileData = array(
        'name' => 'file',
        'filename' => $sFile,
        'type' => 'application/pdf',
        'data' => file_get_contents($sFile)
    );

    $sReturn = pingen_upload('api.pingen.com', 443, "/document/upload/token/" . $sToken, $aPostData, $aFileData);

    /* dirty way of cleaning up headers out of response */
    $aReturn = explode('application/json', $sReturn);
    $aReturn = json_decode(trim($aReturn[1]), true);

    if ($aReturn['error'])
    {
        //an error occured, handle it from here
    }else {
        //go along with your code here
    }