Exemplo n.º 1
0
<?php

require '../lib/StupidHttp/Autoloader.php';
StupidHttp_Autoloader::register();
$server = new StupidHttp_WebServer();
$server->on('GET', '/')->call(function ($r) {
    echo '<html><body>';
    echo '<p>Hello from StupidHttp!</p>';
    echo '<form name="input" action="/hello/" method="post">';
    echo 'What\'s your name?: <input type="text" name="name" />';
    echo '</form>';
    echo '<p>Also: say hello to <a href="/hello/Bob">Bob</a>!</p>';
    echo '</body></html>';
});
$server->onPattern('GET', '/hello/(.+)')->call(function ($c, $m) {
    if ($m[1]) {
        echo '<html><body>';
        echo 'Hello, ' . $m[1] . '<br/>';
        echo '(brought to you via GET)';
        echo '</body></html>';
    }
});
$server->onPattern('POST', '/hello')->call(function ($c) {
    $data = $c->getRequest()->getFormData();
    echo '<html><body>';
    echo 'Hello, ' . $data['name'] . '<br/>';
    echo '(brought to you via POST)';
    echo '</body></html>';
});
$server->run(array('run_browser' => true));
Exemplo n.º 2
0
    print_r($r->getBody());
    echo '</pre>';
    echo '<h1>Forms</h1>';
    echo '<h2>GET</h2>';
    echo '<p>Here is a GET form to see what kind of request it will create.</p>';
    echo '<form name="input_get" action="/" method="get">';
    echo 'First Name: <input type="text" name="first_name" /><br/>';
    echo 'Last Name: <input type="text" name="last_name" /><br/>';
    echo 'Are You Awesome? <input type="checkbox" name="is_awesome" /><br/>';
    echo 'Your Credit Card Number: <input type="password" name="password" /><br/>';
    echo '<input type="submit" value="Send!" name="submit_btn" />';
    echo '</form>';
    echo '<h2>POST</h2>';
    echo '<p>Here is a POST form to see what kind of request it will create.</p>';
    echo '<form name="input_post" action="/" method="post">';
    echo 'First Name: <input type="text" name="first_name" /><br/>';
    echo 'Last Name: <input type="text" name="last_name" /><br/>';
    echo 'Are You Awesome? <input type="checkbox" name="is_awesome" /><br/>';
    echo 'Your Credit Card Number: <input type="password" name="password" /><br/>';
    echo '<input type="submit" value="Send!" name="submit_btn" />';
    echo '</form>';
    echo '</body></html>';
}
$server = new StupidHttp_WebServer();
$server->onPattern('GET', '.*')->call(function ($c) {
    print_request($c->getRequest());
});
$server->onPattern('POST', '.*')->call(function ($c) {
    print_request($c->getRequest());
});
$server->run(array('run_browser' => true));
Exemplo n.º 3
0
<?php

require '../lib/StupidHttp/Autoloader.php';
StupidHttp_Autoloader::register();
$server = new StupidHttp_WebServer();
$server->on('GET', '/')->call(function ($c) {
    echo '<html><body>';
    echo 'Go to <code>/xxx</code> where <code>xxx</code> is an <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">HTTP status code</a>, and see how your browser renders it.';
    echo '</body></html>';
});
$server->onPattern('GET', '/(\\d{3})')->call(function ($c, $m) {
    $c->getResponse()->setStatus(intval($m[1]));
});
$server->run(array('run_browser' => true));