Skip to content

Commit 96aaac4

Browse files
zyuheldg
authored andcommitted
Add Ability to setup custom user-agent (#18)
1 parent 0403bc8 commit 96aaac4

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ Feed::$cacheDir = __DIR__ . '/tmp';
5454
Feed::$cacheExpire = '5 hours';
5555
```
5656

57+
You can setup a User-Agent if needed:
58+
59+
```php
60+
Feed::$userAgent = "FeedFetcher-Google; (+http://www.google.com/feedfetcher.html)";
61+
```
62+
5763
If you like it, **[please make a donation now](https://nette.org/make-donation?to=rss-php)**. Thank you!

src/Feed.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Feed
1515
/** @var string */
1616
public static $cacheDir;
1717

18+
/** @var string */
19+
public static $userAgent = 'FeedFetcher-Google';
20+
1821
/** @var SimpleXMLElement */
1922
protected $xml;
2023

@@ -208,8 +211,7 @@ private static function httpRequest($url, $user, $pass)
208211
if ($user !== null || $pass !== null) {
209212
curl_setopt($curl, CURLOPT_USERPWD, "$user:$pass");
210213
}
211-
$user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36";
212-
curl_setopt($curl, CURLOPT_USERAGENT, $user_agent); // some feeds require a user agent
214+
curl_setopt($curl, CURLOPT_USERAGENT, self::$userAgent); // some feeds require a user agent
213215
curl_setopt($curl, CURLOPT_HEADER, false);
214216
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
215217
curl_setopt($curl, CURLOPT_ENCODING, '');

0 commit comments

Comments
 (0)