Archive: cURL PHP
-
Aug 29, 2011
Comments OffCURL URLS with a get variable
I had the following experience when harvesting urls with a get variable from a page using cUrl. HTML pages will output ampersands as & when the page is read by the curl function. If you code a script to find all hyperlinks, it will use & instead of &, especially using a regular expression search....
-
Aug 29, 2011
Comments OffCURL PHP wrapper for https results
If you want to write a sort of php wrapper to include the results of another http(s) request maybe pointing to a totally different site or just different code (mod_perl with HTML::Mason, in my case) into a php based layout, and just pass-thru all GET and POST variables to the sub-request, the following snippet can...
-
Aug 29, 2011
Comments OffCURL PHP: Get information regarding a specific transfercurl_getinfo — Get information regarding a specific transfer – curl_getinfo()
<?php // Create a curl handle $ch = curl_init('http://www.yahoo.com/'); // Execute curl_exec($ch); // Check if any error occured if(!curl_errno($ch)) { $info = curl_getinfo($ch); echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; } // Close handle curl_close($ch);...
-
Aug 29, 2011
Comments OffExample: Download Website / Webpage Trough CURL PHP
You can access / display any webpage through the following code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44...
-
Aug 29, 2011
Comments OffCURL PHP: Email this page to a friend
Using curl to take snapshots of the current page for emailing the HTML is a clever little idea. (ie: Email this page to a friend) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <?php //to be explained below! session_write_close(); $pageurl = "http://www.site.com/content.php?PHPSESSID=123XYZ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);...
-
Aug 29, 2011
Comments OffcURL to submit to an ASP/ASPX page
For anyone trying to use cURL to submit to an ASP/ASPX page that uses an image as the submit button. Make sure that you have ‘button_name.x’ and ‘button_name.y’ in the post fields. PHP names these fields ‘button_name_x’ and ‘button_name_y’, while ASP uses a dot. Also, as noted above, be sure to include the ‘__VIEWSTATE’ input...
-
Aug 29, 2011
Comments OffCURL PHP : Trouble on server 2003, IIS 6 php_curl
run (as an administrator) php.exe -i > C:\phpinfo.txt and go open C:\phpinfo.txt, look in the file to see if CURL was loading, if it’s there then keep reading. - running inside a text.php script on my IIS server would not show CURL loading - A permissions problem on libeay32.dll and ssleay32.dll was causing the cli...
-
Aug 29, 2011
Comments OffHow to use path for the cookies in CURL PHP LIBRARY ?
<?php $ch = curl_init() ; $myfile = "d:\\mydir\\second_dir\\cookiefile.txt" ; curl_setopt($ch, CURLOPT_COOKIEJAR, $myfile) ;...
-
Aug 29, 2011
Comments OffStop CURL to send messages to the SERVER error log
In order to prevent curl sending messages to the server error log, you need to instruct curl to use a temporary file for output on stderr. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29...
-
Aug 29, 2011
Comments OffA simple whois/domain availability check using cURL PHP
CURL Register Your domain but check its availability: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 <?php echo check_domain('www.imjan.com'); // Instant Example of using check_domain() function function check_domain($domain) { $data = 'http://'.$domain;...
-
Aug 29, 2011
Comments OffUsing PHP cURL to read and write RSS feed XML
Simple Example to read RSS feed and write in you local system. 1 2 3 4 5 6 7 8 9 10 11 <?php $ch = curl_init("http://feeds.feedburner.com/bagesh-blog"); // Change the RSS FEED URL $fp = fopen("file.txt", "w"); // Change Filename if you want curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp);...
-
Aug 29, 2011
Comments OffDisadvantage of cURL Library PHP example
Although it has been noted that cURL outperforms both file_get_contents and fopen when it comes to getting a file over a HTTP link, the disadvantage of cURL is that it has no way of only reading a part of a page at a time. For example, the following code is likely to generate a memory...
-
Aug 29, 2011
Comments OffTo follow ALL redirects using CURL brings up a lot of special cases
To follow ALL redirects using CURL brings up a lot of special cases. Here’s a function that takes everything into account (even javascript redirects) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31...
-
Aug 29, 2011
Comments OffFatal Error: Call to Undefined Function Curl_init() in E:\wamp\www\mytest\index.php on Line 10
If you see this error then you have not installed / enabled CURL Library. It’s very simple to install it. Just go to your php.ini and 1 2 3 ;extension=php_curl.dll // default setting in php.ini extension=php_curl.dll // Remove semicolon(;) and then restart you...
-
Aug 29, 2011
Comments OffWhat Are the Advantages of CURL Library?
PHP supports libcurl is a library that allows you to connect and communicate to many different types of servers with many different types of protocols. LIBCURL (CURL LIBRARY PHP) currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. LIBCURL (CURL LIBRARY PHP) also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP...
-
Aug 29, 2011
Comments OffcURL PHP: Connect to a Secure Server
If you want to connect to a secure server for posting info/reading info, you need to make cURL with the openSSL options. Then the sequence is nearly identical to the previous example (except http_S_://, and possibly add the useragent): 1 2 3 4 5 <?php curl_setopt($ch, CURLOPT_URL,"https://example.com"); //some sites only accept your request if your...
-
Aug 29, 2011
Comments OffcULR Library PHP : Check Website Status
function checkDomainLiveStatus($url) { $agent = “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”;$ch=curl_init(); curl_setopt ($ch, CURLOPT_URL,$url ); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch,CURLOPT_VERBOSE,false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $page=curl_exec($ch); //echo curl_error($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode>=200 && $httpcode<300) return true; else return false; } if(checkDomainLiveStatus(“http://www.yourdomain.com”)) { echo “Website OK”.”n”; } else { /* if...
-
Aug 29, 2011
Comments OffPOST in multipart/form-data mode using CURL PHP
1 <?php curl_setopt($ch,CURLOPT_POSTFIELDS,$post); ?> where $post is an array : 1 2 3 4 5 6 <?php $post['key1'] = 'data1'; // like a text field in a POST $post['file1'] = '@filename1' // upload filename1...
-
Aug 29, 2011
Comments OffSimple CURL PHP Example
Following code returns the curl output as a string. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <?php // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "example.com"); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output...
-
Apr 24, 2011
Comments Offhow to show shipping information to paypal express checkout
Customizing Express Checkout You can specify options in Express Checkout API requests that change the appearance, behavior, and flow of the checkout process. PayPal Review Page Order Details Providing Gift Options Getting Buyer Consent to Receive Promotional Email Providing Your Customer Service Number Adding a Survey Question PayPal Page Style Changing the Locale Handling Shipping...