国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

Zend Framework中如何判斷URL是否設置了轉發

2024-05-04 21:48:08
字體:
來源:轉載
供稿:網友

下面我來介紹一個Zend Framework中如何判斷URL是否設置了轉發,有需要學習的朋友可參考.

發送HTTP請求,代碼如下:

  1. $client    = new Zend_Http_Client(); 
  2. $client->setUri($url); 
  3. $client->setConfig(array('maxredirects' => 1)); 
  4. $response  = $client->request(); 
  5. if ( $response->isRedirect() ) { 
  6.    echo "設置了轉發"
  7. else { 
  8.    echo "沒有設置轉發"

在這里如果不設置maxredirects參數,Zend默認的最大跳轉數為5,就是在每次請求的時候,如果該地址設置了轉發,他會讀取轉發到的新地址,然后再對這個地址發起請求,循環做這個操作,直至新地址沒有設置轉發或者循環超過了5次才會返回最后一次的請求數據.

這樣的話,如果我只想獲取某個域名是否設置了轉發,那么就必須設置下maxredirects這個參數了.

Zend Framework代碼如下:

  1. public function request($method = null) 
  2.     { 
  3.         if (! $this->uri instanceof Zend_Uri_Http) { 
  4.             /** @see Zend_Http_Client_Exception */ 
  5.             require_once 'Zend/Http/Client/Exception.php'
  6.             throw new Zend_Http_Client_Exception('No valid URI has been passed to the client'); 
  7.         } 
  8.  
  9.         if ($method) { 
  10.             $this->setMethod($method); 
  11.         } 
  12.         $this->redirectCounter = 0; 
  13.         $response = null; 
  14.         // Make sure the adapter is loaded 
  15.         if ($this->adapter == null) { 
  16.             $this->setAdapter($this->config['adapter']); 
  17.         } 
  18.  
  19.         // Send the first request. If redirected, continue. 
  20.         do { 
  21.             // Clone the URI and add the additional GET parameters to it 
  22.            //省略一萬字 
  23.         } while ($this->redirectCounter < $this->config['maxredirects']); 
  24.  
  25.         return $response
  26.     } 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三原县| 文成县| 石阡县| 祥云县| 南开区| 施甸县| 青冈县| 拜城县| 枣阳市| 河北省| 南昌县| 横山县| 台南县| 樟树市| 宜兴市| 大同市| 三都| 潜江市| 抚顺市| 岳池县| 布拖县| 延川县| 井研县| 衡南县| 康马县| 万州区| 腾冲县| 东乡| 镇巴县| 德江县| 四川省| 温州市| 固始县| 宾川县| 麻城市| 巴林右旗| 庆安县| 湖南省| 西畴县| 应用必备| 望奎县|