How to stop form resubmission on page refresh in php

Its a major problem with all new programmers . Usually if we do not use captcha in a form than after form submission if user refresh the page than it again submit the data in database or send mail means the from submits again and again if you refresh the page . But i have a very simple and solid fix for this. Lets see the script below to stop from resubmission without clicking on submit button.

on the page with form write this code.

Read the rest of this entry »

PHP’s cURL module to fetch homepage of any website

We can use curl to fetch homepage of any website.

Following code returns the curl output as a string.

<?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 = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);
?>

How to Post form data without using cURL

Its very easy to post form data without using curl If your hosting server does not come with cURL installed and you also don’t have access to server in order to install it, there are alternatives.

One of them is using PHP’s functions fsockopen() and fputs() to send properly formatted data to a remote server. Here is a sample of code that does just this:

Read the rest of this entry »

Send post form data using curl

<?php

if(isset($_POST['Name'])) $Name = urlencode($_POST['Name']);

if(isset($_POST['Email'])) $Email = urlencode($_POST['Email']);

if(isset($_POST['Message'])) $Message= urlencode(htmlentities($_POST['Message']));

$Curl_Session = curl_init(’http://www.site.com/cgi-bin/waiting.php’);

curl_setopt ($Curl_Session, CURLOPT_POST, 1);

curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS,

“Name=$Name&Email=$Email&Message=$Message”);

curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt ($Curl_Session, CURLOPT_RETURNTRANSFER, 1);

curl_exec ($Curl_Session);

curl_close ($Curl_Session);

?>

In this example you can see one constant CURLOPT_RETURNTRANSFER.

if you put the value of CURLOPT_RETURNTRANSFER to 1 it means the output of this process will not be print directly.

To print the result you first take the result in a variable and than print that variable. And if you put

the value of CURLOPT_RETURNTRANSFER to 0 it means the output of this process will print automatically after successfully execution of curl.

How to use curl to Query Remote Servers

Curl is very useful to connect to a remote server and get required data.As with all other full featured browsers curl has support for proxies. Proxy servers are buffers between the requesting client and the web server. Proxy servers are used for a variety of reasons including companies restricting web access to people wanting to appear anonymous.

There are a few curl options to set when using a proxy. First to enable use of a proxy in curl use the option CURLOPT_HTTPPROXYTUNNEL. Second set the proxy with the option CURLOPT_PROXY. If you need to set authentication information use the option CURLOPT_PROXYUSERPWD. CURLOPT_PROXYUSERPWD expects a string in the format of user:password. HTTP proxies are default, to use a SOCKS proxy use the CURLOPT_PROXYTYPE option.

Read the rest of this entry »