Jump to content

[SOLVED] CURL help please


dtdetu

Recommended Posts

hello i am trying to make a post script but somehow it doesnt work, can u check and tell me what the problem is.

The form i am posting is this :

<form method='POST' action=''><input type='number' name='amount' id='amount'> <input type=submit name='send' id='send' value='Send'></form>

 

This code posts the data but it brakes the page, i mean when i check result.htm half of the page isnt there.

 

         curl_setopt ($ch, CURLOPT_URL, 'http://site.com/page.php');
	  curl_setopt ($ch, CURLOPT_REFERER, 'http://site/page.php');
	  curl_setopt ($ch, CURLOPT_POST, TRUE);
                  curl_setopt ($ch, CURLOPT_POSTFIELDS, "amount=1&send=Send");
                 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
                 $result = curl_exec ($ch);
               file_put_contents("result.htm", $result);


This code doesnt even post.

 

         curl_setopt ($ch, CURLOPT_URL, 'http://site.com/page.php');
	  curl_setopt ($ch, CURLOPT_REFERER, 'http://site/page.php');
	  curl_setopt ($ch, CURLOPT_POST, TRUE);
                  curl_setopt ($ch, CURLOPT_POSTFIELDS, "amount=1");
                 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
                 $result = curl_exec ($ch);
               file_put_contents("result.htm", $result);


 

 

Link to comment
https://forums.phpfreaks.com/topic/132830-solved-curl-help-please/
Share on other sites

There is a good chance there might be a redirect in there, a time out issue or possibly something checking for a cookie.  I'd try the following additions...

 

<?php
    ######### Set up field values #########
$fields = ""amount=1&send=Send";
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
$ref = "http://site/page.php";


    ######### Prepare curl settings and variables #########
$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://site/page.php");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); //create a cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_MAXREDIRS, 4); //this sets a maximum on the number of redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); //this will allow you to follow a redirect
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); //increase the timeout
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); //setting this to 1 makes it display ON screen.  Setting it to zero does not.
$buffer = curl_exec($ch);
curl_close($ch);
?>

it posts but also removes some codes from the post page, its about fields i think, if i send

  $fields = "amount=1"; it doesnt post but doesnt break the page also , does anyone have any idea about this?

it removes from the beginning of the page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="0">
-->
<title>title</title>
<!--<link href="/css.dcss?css=s" rel="stylesheet" type="text/css">
<link href="/css.dcss" rel="stylesheet" type="text/css">-->
<script type="text/javascript" src="js.js"> </script>
<!--<script src="js2.js" language="JavaScript" type="text/javascript"></script>-->
<style type="text/css">
<!--
@import url("a.css");
-->
</style>
<script type="text/javascript">
<!--
var border = RUZEE.ShadedBorder.create({ corner:8, shadow:16,  border:2 });
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
function breakout_of_frame() {
  if 

 

and some code from the end of the page, what does cause this anyone know?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.