Archive for the ‘ CURL PHP Examples ’ Category
Check or Uncheck All in a Group of Checkbox in JavaScript
on March 11, 2010
JavaScript code to be kept before head tag. <SCRIPT LANGUAGE="JavaScript"> function CheckAll(chk) { for (i = 0; i < chk.length; i++) chk[i].checked = true ; } function UnCheckAll(chk) { for (i = 0; i < chk.length; i++) chk[i].checked = false ; } </script> HTML Code: <form name="myform" action="checkboxes.asp" method="post"> <b>Scripts for Web design and programming</b><br> <input type="checkbox" name="check_list" value="1">ASP<br> <input type="checkbox" name="check_list" value="2">PHP<br> …
cULR Library PHP : Check Website Status
on March 6, 2010
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 website is down*/ echo "Website DOWN"; }
cURL PHP: Connect to a Secure Server
on February 20, 2010
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): <?php curl_setopt($ch, CURLOPT_URL,"https://example.com"); //some sites only accept your request if your browser looks legit, so send a useragent profile… curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; …
What Are the Advantages of CURL Library?
on February 17, 2010
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 uploading (this can also be done with PHP’s …
Using Javascript to POST Data Between Pages
on February 17, 2010
The following is a simple example of how to submit data from one HTML page to another using the POST method from Javascript. Normally, if data needs to be sent from one HTML page to another, it is done by appending the information to the query parameter of the the URL in the familiar “name=value†format. e.g. <a href="post.aspx?user=peter&cc=aus">Click</a> Although this works fine, …
Fatal Error: Call to Undefined Function Curl_init() in E:\wamp\www\mytest\index.php on Line 10
on February 15, 2010
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 ;extension=php_curl.dll // default setting in php.ini extension=php_curl.dll // Remove semicolon(;) and then restart you server CURL is installed.
To follow ALL redirects using CURL brings up a lot of special cases
on January 20, 2010
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) <?php function get_final_url( $url, $timeout = 5 ) { $url = str_replace( "&", "&", urldecode(trim($url)) ); $cookie = tempnam ("/tmp", "CURLCOOKIE"); $ch = curl_init(); curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" ); curl_setopt( $ch, …
Disadvantage of cURL Library PHP example
on December 20, 2009
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 limit error: <?php $ch = curl_init("http://www.example.com/reallybigfile.tar.gz"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, …
Using PHP cURL to read and write RSS feed XML
on December 6, 2009
Simple Example to read RSS feed and write in you local system. <?php $ch = curl_init("http://feeds.feedburner.com/imjan"); // 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); ?>
A simple whois/domain availability check using cURL PHP
on November 21, 2009
CURL Register Your domain but check its availability: <?php echo check_domain(‘www.imjan.com’); // Instant Example of using check_domain() function function check_domain($domain) { $data = ‘http://’.$domain; // Create a curl handle to a non-existing location $ch = curl_init($data); // Execute curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); // Check if any error occured if(curl_errno($ch)) { return ‘<span style="color:#22c922">The domain is available!</span>’; } else { return ‘<span style="color:#c92222">The domain …

