Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added checks for UPDATE_FOPEN and UPDATE_FSOCKOPEN.

  • Loading branch information...
commit f2f0cb363e87cab979e56879f15fbc5d365ab054 1 parent 8beec27
authored February 20, 2012

Showing 1 changed file with 42 additions and 38 deletions. Show diff stats Hide diff stats

  1. 80  src/phpbrowscap/Browscap.php
80  src/phpbrowscap/Browscap.php
@@ -601,47 +601,51 @@ protected function _getRemoteData($url)
601 601
 					throw new Browscap_Exception('Cannot open the local file');
602 602
 				}
603 603
 			case self::UPDATE_FOPEN:
604  
-				$file = file_get_contents($url);
605  
-
606  
-				if ($file !== false) {
607  
-					return $file;
  604
+				if (ini_get('allow_url_fopen') && function_exists('file_get_contents')) {
  605
+					$file = file_get_contents($url);
  606
+	
  607
+					if ($file !== false) {
  608
+						return $file;
  609
+					}
608 610
 				} // else try with the next possibility (break omitted)
609 611
 			case self::UPDATE_FSOCKOPEN:
610  
-				$remote_url = parse_url($url);
611  
-				$remote_handler = fsockopen($remote_url['host'], 80, $c, $e, $this->timeout);
612  
-
613  
-				if ($remote_handler) {
614  
-					stream_set_timeout($remote_handler, $this->timeout);
615  
-
616  
-					if (isset($remote_url['query'])) {
617  
-						$remote_url['path'] .= '?' . $remote_url['query'];
618  
-					}
619  
-
620  
-					$out = sprintf(
621  
-						self::REQUEST_HEADERS,
622  
-						$remote_url['path'],
623  
-						$remote_url['host'],
624  
-						$this->_getUserAgent()
625  
-					);
626  
-
627  
-					fwrite($remote_handler, $out);
628  
-
629  
-					$response = fgets($remote_handler);
630  
-					if (strpos($response, '200 OK') !== false) {
631  
-						$file = '';
632  
-						while (!feof($remote_handler)) {
633  
-							$file .= fgets($remote_handler);
  612
+				if (function_exists('fsockopen')) {
  613
+					$remote_url = parse_url($url);
  614
+					$remote_handler = fsockopen($remote_url['host'], 80, $c, $e, $this->timeout);
  615
+	
  616
+					if ($remote_handler) {
  617
+						stream_set_timeout($remote_handler, $this->timeout);
  618
+	
  619
+						if (isset($remote_url['query'])) {
  620
+							$remote_url['path'] .= '?' . $remote_url['query'];
  621
+						}
  622
+	
  623
+						$out = sprintf(
  624
+							self::REQUEST_HEADERS,
  625
+							$remote_url['path'],
  626
+							$remote_url['host'],
  627
+							$this->_getUserAgent()
  628
+						);
  629
+	
  630
+						fwrite($remote_handler, $out);
  631
+	
  632
+						$response = fgets($remote_handler);
  633
+						if (strpos($response, '200 OK') !== false) {
  634
+							$file = '';
  635
+							while (!feof($remote_handler)) {
  636
+								$file .= fgets($remote_handler);
  637
+							}
  638
+	
  639
+							$file = str_replace("\r\n", "\n", $file);
  640
+							$file = explode("\n\n", $file);
  641
+							array_shift($file);
  642
+	
  643
+							$file = implode("\n\n", $file);
  644
+	
  645
+							fclose($remote_handler);
  646
+	
  647
+							return $file;
634 648
 						}
635  
-
636  
-						$file = str_replace("\r\n", "\n", $file);
637  
-						$file = explode("\n\n", $file);
638  
-						array_shift($file);
639  
-
640  
-						$file = implode("\n\n", $file);
641  
-
642  
-						fclose($remote_handler);
643  
-
644  
-						return $file;
645 649
 					}
646 650
 				} // else try with the next possibility
647 651
 			case self::UPDATE_CURL:

0 notes on commit f2f0cb3

Please sign in to comment.
Something went wrong with that request. Please try again.