国产探花免费观看_亚洲丰满少妇自慰呻吟_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.     } 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建德市| 虞城县| 太仓市| 广宗县| 泾源县| 明光市| 宜君县| 晋江市| 屏山县| 龙陵县| 洞头县| 包头市| 宜丰县| 阿克| 廊坊市| 巩义市| 潮州市| 夹江县| 正宁县| 夹江县| 安吉县| 绥芬河市| 宁乡县| 阿勒泰市| 徐闻县| 文登市| 大方县| 夹江县| 南漳县| 永川市| 错那县| 蒲江县| 泰宁县| 大港区| 台南县| 焉耆| 平山县| 翁牛特旗| 塔河县| 娄底市| 台中市|