Pagine: [1]
Stampa
Autore Discussione: [PHP] httpBuilder Class (curl Interface)  (Letto 635 volte)
Matrix86
Amministratore
Full Member
*****

Popolarità: +7/-0
Scollegato Scollegato

Messaggi: 133



WWW
« inserito:: Settembre 27, 2008, 13:18:24 »

Ieri notte mi aggiravo per la mia città con una bella birra e ripensando a un post con The_Stooge, in cui si discuteva se era meglio usare curl o creare la richiesta http a mano, mi è venuta un'idea molto semplice da realizzare.
Come ImgManipulator Class che semplificava l'uso delle GD, httpBuilder vuole essere una facilitazione per l'uso di Curl (non che sia difficile da usare).
Come vedrete creare una richiesta post, get e usare i cookie è estremamente semplice. Basta inserire in un array tutti i valori da passare tramite Get, Post e Cookie. Per esempio se dobbiamo creare una richiesta Post del seguente form:

Codice:
<form action='search.php' method='POST'>
<input type='text' name='testo' value='' />
<input type='submit' name='invia' value='Invia' />
</form>

bastano poche righe:
Codice: (post.php)
<?php
include( 'httpBuilder.Class.php' );
$req = new httpBuilder();

// Set Url
$req->setUrl'http://www.tuxmealux.net/search.php' );

// Add Post Data
$postdata = array( 'testo' => 'Questo è un testo''invia' => 'Invia' );
$req->addPostData$postdata );

// Return response and don't delete header
$req->setReturnTRUETRUE );

echo 
$req->sendRequest();

$req->close();
?>

Lo stesso vale per le richieste get e cookie.
In parole povere questa libreria interfaccia le funzioni di Curl più usate. Good work!  Ghigno

DOWNLOAD httpBuilder Class

Citazione di: Lista delle funzioni
/*
 * Function List:
 *
 * - addGetData( array $data );
 * - resetGetData( );
 * - addPostData( array $data );
 * - resetPostData( );
 * - addCookieFile( string $filename );
 * - saveCookie( string $filename );
 * - addCookieData( array$data );
 * - resetCookie( );
 * - setUrl( string $url );
 * - setPort( integer $port );
 * - setReturn( boolean $return, [boolean $showHeader = FALSE], [boolean $followLocation = TRUE] );
 * - setProxy( string $proxy, [integer $port = 80] );
 * - setUserAgent( string $usrAgent );
 * - setReferer( string $referer );
 * - sendRequest( );
 * - Info( boolean $print );
 * - close( );
 *
 */
« Ultima modifica: Settembre 27, 2008, 13:21:04 da Matrix86 » Registrato


Pagine: [1]
Stampa
 
Vai a: