Originally posted by badboy
Perhaps I am confused because remember reading someplace how some websites process credit cards by using cURL to post the cc data to the processing gateway and getting the response/approval /error codes back from the gateway server then parsing the response and then sending data to the browser.
This is the same process I am trying to accomplish.
Any thoughts ?
Thanks
You said it yourself, parsing the response. What they get back is the html, then they look in the html for the information they want. Here is an example, not related to credit cards.
This function will check and see if your page's html validates with http://validator.w3.org/
<?php
function check_html_compliance($url) {
$query_string = '';
//rebuild the query string for the page we are viewing
foreach($_GET as $key => $val)
$query_string .= '&' . $key . '=' . $val;
//if we have a query string then we need to setup the
//url to check appropriatly
if($query_string != '') {
$query_string = substr($query_string,1);
$referer = $url . '?' . $query_string;
}
//if there is no query string then we can just use the
//url that was passed in.
else
$referer = $url;
//okay now we're ready to do our curl work.
$ch = curl_init('http://validator.w3.org/check?uri=referer');
//let's have the html handed back instead of printed
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//tell the validator where we came from
curl_setopt($ch,CURLOPT_REFERER,$referer);
//if we are given a header redirect we would like
//to obey the command
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
//we're only going to give the validator 10 seconds
//to respond so our page doesn't hang if the
//validator is busy
curl_setopt($ch,CURLOPT_TIMEOUT,10);
//let's get the html and close out the curl session
$output = curl_exec($ch);
curl_close($ch);
//here we parse the html. If we find the string
//"This page is valid" then we know that the
//page validated successfully, so we grab the
//link to display the validated image on our page
//and turn &**; back into html code
if(eregi('This page is valid',$output)) {
$start = strpos($output,'<p>') + 9;
$end = strpos($output,'</p>') - $start;
$retval = html_entity_decode(substr($output,$start,$end));
}
//if we get here then we know that the page's html
//is not valid.
else {
$retval = 'Not Valid Code';
} //end if
//return the information we gathered from parsing
//the html that was returned to us.
return $retval;
} //end check_html_compliance
?>
I hope that helps you, especially since I just added all those comments to explain what I was doing.