/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /****************************************** * POST TO REMOTE SCRIPT ******************************************/ //fake data to send via cURL $post = 'var1=hello&var2=world'; //replace with your post destination url $url = "http://example.com/script.php"; //start cURL //define curl: set where the post is going //define curl: set that you want the response //to be store in a variable and not display on screen //define curl: set what you are sending //If the post was not successful curl_exec will return false. //If successful store response in variable //close the connection //Trim the response from excess white space //NOTE:It may be necessary to do further sanitizing of the string //enable error reporting //parse the xml response string //store the original xml in an array //if simplexml_load_string() fails, it returns false. //if it returns false, collect the errors and print them to the screen if (!$doc) { foreach ($errors as $error) { echo display_xml_error($error, $xml); } }else{ //Successfull parsed the xml string } }else{ //There was a problem with cURL executing. Do you have cURL on this server? echo "cURL was not able to execute"; //close connection } //Helper Function For Displaying the Errors function display_xml_error($error, $xml){ $return = $xml[$error->line - 1] . "\n"; switch ($error->level) { case LIBXML_ERR_WARNING: $return .= "Warning $error->code: "; break; case LIBXML_ERR_ERROR: $return .= "Error $error->code: "; break; case LIBXML_ERR_FATAL: $return .= "Fatal Error $error->code: "; break; } "\n Line: $error->line" . "\n Column: $error->column"; $return .= "\n File: $error->file"; } return "$return\n\n--------------------------------------------\n\n"; } ?>