clox / hicurl
hicurl is an object-oriented wrapper of the PHP cURL extension.Its main feature however is the ability to save requested pages and it also includes a javascript "class" for viewing the saved data.
Installs: 69
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:CSS
- dev-master
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.1
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.0
- v3.3.0
- v3.1.0
- v3.0.0
- 2.x-dev
- v2.0.3-a
- v2.0.2-a
- v2.0.1
- v2.0.1-a
- v2.0.0-a
- v1.6.0
- v1.5.0
- 1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-prepare_for_v2
- dev-complete_separating_customData_and_also_remove_static_methods
- dev-separate_customData_from_compile()
- dev-Store_history_as_separate_files
This package is auto-updated.
Last update: 2025-05-16 00:54:52 UTC
README
A library that aims in making cURL-requests a piece of cake while also allowing for saving the fetched pages along with headers and postdata to files for later viewing. It essentially is a PHP wrapper class for cURL, and a javascript "class" that displays the saved data nicely.
Getting Started
###Simple Usage To use Hicurl on the PHP side you simply need to include hicurl.php inside the src folder:
require_once 'hicurl/src/hicurl.php';
Then you can do something like the following to begin loading some pages:
$hicurl=new Hicurl(); $google=$hicurl->loadSingle('www.google.com'); The $google-variable will now hold an associative array looking like: [ 'content'=>page-content ,'headers'=>all the received headers ,'error'=>false for success, otherwise a description of the error ]
It is also easy sending post-data. If an object is passed to the second parameter the request will be sent as POST with that data:
require_once 'hicurl/src/hicurl.php'; $hicurl=new Hicurl(); $hicurl->loadSingle('http://www.htmlcodetutorial.com/cgi-bin/mycgi.pl',['foo'=>'bar']);
###Settings
There's a bunch of settings that can be used. These can be passed or like this:
$hicurl=new Hicurl(['cookie'=>'cookies/cookie.txt']);
Any calls made with that instance will now save cookies in and send cookies from that file. Settings can be changed after instance-creation:
$hicurl->settings(['cookie'=>'cookies/muffin.txt']);
Lastly, they may also be passed to the load call in which case they will be merged with the settings of the instance during that call only:
$hicurl->loadSingle('www.google.com',null,['cookie'=>'cookies/macarone.txt']);
###Static usage Most methods also have static counterparts which can be convenient if only a single call is to be made:
$result=Hicurl->loadSingleStatic($url,$postData,['cookie'=>'cake.txt']);
It's equivalent without hicurl would be something along the lines of:
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLINFO_HEADER_OUT,true); curl_setopt($ch,CURLOPT_COOKIEFILE],'cake.txt'); curl_setopt($ch,CURLOPT_COOKIEJAR]'cake.txt'); $postDataString=""; foreach ($postData as $key=>$value) { $postDataString.=urlencode($key)."=".urlencode($value)."&"; } curl_setopt($ch,CURLOPT_POSTFIELDS, trim($string, ",")); $result=['content'=>curl_exec($ch),'headers'=>curl_getinfo($ch)]; curl_close($ch);
"Whew!" ###Saving history Saving data is easy too. For starters we need one additional setting:
//set a history output filepath. This setting will be used for subsequent load-calls and will make them save data to that file. $hicurl->settings(['history'=>'history/myHistoryFile']); //load a couple pages. they will be saved to myHistoryFile $hicurl->loadSingle("www.google.com"); $hicurl->loadSingle("www.facebook.com"); //When we are done writing to the file we need to "compile it". //This puts it in a closed state, and also compresses it. //This is the state it is sent to the client in. $hicurl->compileHistory();
###Sending history There's some easy job to be done for sending the data to the client. Here's one way of doing it:
getHistory.php
require_once 'hicurl/src/hicurl.php'; Hicurl::serveHistory('history/myHistoryFile');
That's what we need for sending the data. Though simply loading this page in the browser wont help much, so we will need to do the following... ###Viewing history To be able to view the data in a meaningful way we will use the javascript hicurl-class. We need to load some files to use it and then write a tiny bit more code.
<!--This is the js "class" used for viewing the history--> <script src="hicurl/src/hicurl.js"></script> <!--...it needs this css-file to display things correctly--> <link rel="stylesheet" type="text/css" href="hicurl/src/hicurl.css"> <!--It also required jQuery--> <script src="hicurl/src/libs/jquery-1.11.2.min.js"></script> <!--.And jquery easy UI--> <script src="hicurl/src/libs/jquery.easyui.min.js"></script> <!--...along with it's css-file--> <link rel="stylesheet" type="text/css" href="../../src/libs/easyui.css"> <!--This can optionally be included and will make html-code display better--> <script src="hicurl/src/libs/beautify-html.js"></script> <!--Now for initiating the class--> <script> //it expects a DOM-element in its first parameter, where everything will be rendered unto. //As second parameter we will need to pass a url-string where it will fetch the history-data from. hicurl=new Hicurl(document.body,"getMyHistory.php"); //We will need to create that page, e.g. "getHistory.php" in this case, and make it send the data. </script>