好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Zend Framework中如何判断URL是否设置了转发 - php高级

Zend Framework中如何判断URL是否设置了转发

下面我来介绍一个Zend Framework中如何判断URL是否设置了转发,有需要学习的朋友可参考.

发送HTTP请求,代码如下:

$client     =  new  Zend_Http_Client();  $client ->setUri( $url );  $client ->setConfig( array ( 'maxredirects'  => 1));  $response   =  $client ->request();  if  (  $response ->isRedirect() ) {      echo   "设置了转发" ;  }  else  {      echo   "没有设置转发" ;  } 

在这里如果不设置maxredirects参数,Zend默认的最大跳转数为5,就是在每次请求的时候,如果该地址设置了转发,他会读取转发到的新地址,然后再对这个地址发起请求,循环做这个操作,直至新地址没有设置转发或者循环超过了5次才会返回最后一次的请求数据.

这样的话,如果我只想获取某个域名是否设置了转发,那么就必须设置下maxredirects这个参数了.

Zend Framework代码如下:

public   function  request( $method  = null)      {           if  (!  $this ->uri instanceof Zend_Uri_Http) {               /** @see Zend_Http_Client_Exception */                require_once   'Zend/Http/Client/Exception.php' ;               throw   new  Zend_Http_Client_Exception( 'No valid URI has been passed to the client' );          }             if  ( $method ) {               $this ->setMethod( $method );          }           $this ->redirectCounter = 0;           $response  = null;           // Make sure the adapter is loaded            if  ( $this ->adapter == null) {               $this ->setAdapter( $this ->config[ 'adapter' ]);          }             // Send the first request. If redirected, continue.            do  {               // Clone the URI and add the additional GET parameters to it               //省略一万字           }  while  ( $this ->redirectCounter <  $this ->config[ 'maxredirects' ]);             return   $response ;      } 

查看更多关于Zend Framework中如何判断URL是否设置了转发 - php高级的详细内容...

  阅读:45次