hinom 5 Denunciar post Postado Setembro 14, 2009 006 - Library Request app\lib\Request.php <?php /** Request URL Parameters Class * * company: Foo Bar corp. * autor: mr. foo * email: info@foo.bar * website: foo.bar * updated: 2004-03-25 04:03:12 - mr. foo * * Methods Extract */ class Request { public $method = false; public $parameter = false; private $mthd; function Extract( ) { if( isset( $_SERVER['REQUEST_METHOD'] ) ) { if( $this->method != 'FILES' ) { $this->mthd = strtoupper( $_SERVER['REQUEST_METHOD'] ); if( $this->method and strtoupper( $this->method ) != $this->mthd ) { return false; } if( !$this->method ){ $this->method = $this->mthd; } } $this->mthd = $GLOBALS['_' . $this->method]; if( is_array( $this->mthd ) and count( $this->mthd ) > 0 ) { if( $this->parameter ) { if( isset( $this->mthd[$this->parameter] ) ) { return $this->mthd[$this->parameter]; } }else{ return $this->mthd; } } } return false; } } ?> Usage Sample Method GET <?php // get parameter 'foo' from GET method // http://foo.bar/?foo=bar $rq = new Request; $rq -> method = 'GET'; $rq -> parameter = 'foo'; echo $rq -> Extract(); // display "bar" ?> Method POST <?php $rq = new Request; $rq -> method = 'POST'; $rq -> parameter = 'foo'; echo $rq -> Extract(); // display "foo" when sent by POST method only. ?> Undefined method (both methods) <?php $rq = new Request; $rq -> parameter = 'foo'; echo $rq -> Extract(); // display foo value for both methods. ?> Undefined method and parameter <?php $rq = new Request; echo $rq -> Extract(); // return and array, regardless of method. ?> http://forum.imasters.com.br/public/style_emoticons/default/seta.gif Índice http://forum.imasters.com.br/public/style_emoticons/default/seta.gif 005 - Módulo "Home" http://forum.imasters.com.br/public/style_emoticons/default/seta.gif 007 - Rewrite Rules (.htaccess) Compartilhar este post Link para o post Compartilhar em outros sites