Пример #1
0
        // Set up the request and prepare to read it from socket
        $req = new Cherry\Web\Request();
        $host = stream_socket_get_name($client, true);
        $req->setRemoteIp($host);
        // Read until we got the whole request. The isRequestComplete() method
        // will return true once it has detected a full request.
        while (!$req->isRequestComplete()) {
            $req->createFromString(fread($client, 24000), true);
        }
        // If we don't have a request method this was probably just a ping to
        // get the certificate, leaving us with an empty request which doesn't
        // need a response.
        if ($req->getRequestMethod()) {
            // Create an appropriate response based on the request.
            $rsp = $req->createResponse();
            // Set up our response. The camel case is translated into the proper
            // headers, so contentType becomes Content-Type.
            $rsp->contentType = "text/html";
            $rsp->server = "Cherry HTTPS Example Server";
            $rsp->connection = "close";
            $rsp->setContent($req->asHtml());
            // Respond to client
            fwrite($client, $rsp->asHttpResponse(true));
            // Output the request and the response as text (for debugging)
            echo "" . CliUtils::numberLines($req->asText(), "%3d ") . "\n";
            echo "" . CliUtils::numberLines($rsp->asText(), "%3d ") . "\n";
        }
        // Close the connection
        fclose($client);
    }
}
Пример #2
0
#!/usr/bin/php
<?php 
//LOADER:BEGIN
if (!@(include_once "lib/bootstrap.php")) {
    $libpath = getenv('CHERRY_LIB');
    if (!$libpath) {
        fprintf(STDERR, "Define the CHERRY_LIB envvar first.");
        exit(1);
    }
    require_once $libpath . '/lib/bootstrap.php';
}
//LOADER:END
// Example: Crypto
$str = 'Hello World';
$key = 'FooBar';
$enc = \Cherry\Crypto\Algorithm::tripledes($key)->encrypt($str);
$dec = \Cherry\Crypto\Algorithm::tripledes($key)->decrypt($enc);
$encs = \Cherry\Cli\CliUtils::printable($enc);
echo "{$str} -> {$encs} -> {$dec}\n";
// Example: Crypto (#2)
$str = 'Hello World';
$key = 'FooBar';
$ca = new \Cherry\Crypto\Algorithm('tripledes', $key);
$enc = $ca->encrypt($str);