Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vjeux/phpfiledownload
file_get_contents handling cookies and posts
https://github.com/vjeux/phpfiledownload
Last synced: about 1 month ago
JSON representation
file_get_contents handling cookies and posts
- Host: GitHub
- URL: https://github.com/vjeux/phpfiledownload
- Owner: vjeux
- Created: 2010-11-25T14:44:22.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2012-01-31T21:15:03.000Z (almost 13 years ago)
- Last Synced: 2024-04-14T15:07:23.900Z (9 months ago)
- Language: PHP
- Homepage: http://blog.vjeux.com/
- Size: 93.8 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[phpFileDownload](http://blog.vjeux.com/) - file_get_content replacement for spiders
================================file_get_contents works well for static page but when working with spider scripts that gather data from real websites, it doesn't meet all the requirements.
phpFileDownload has been written to make those tasks convenient:
* Automatic Cookies Management
* Easy to do POST Data
* Handling Location Redirect### Prototype
The class is extremely simple. There is a get() function that works like file_get_contents with a second parameter to tell the POST content. The cookies are stored in a simple associative array.
class FileDownload() {
public function get($url, $post_content = NULL);
public $cookies;
}### Example
A common task your spider want to execute is to login on a forum and access private pages there. Doing this is achieved with only two functions call.
```ruby
$fd = new FileDownload();// Login Phase:
// It logs in by following the many redirects
// and by settings all the required cookies$fd->get('http://some-forum.com/login.php?do=login', // URL
'vb_login_username=vjeux&vb_login_password=!@#$%^&*'); // POST Data// Optional:
// You can view / edit the cookies using the variable $fd->cookiesprint_r($fd->cookies);
// Spider Phase:
// You are now logged in, get any page you need$page = $fd->get('http://some-forum.com/search.php?do=finduser&userid=12345');
```