[Help]posting with curl...

Discussion in 'PHP' started by linkinpark2014, Jan 29, 2009.

  1. #1
    hi,
    i have problem posting with a site using curl
    here is what i did:


    //---------------------posting curl
    $url="sample.com/addreply.aspx";
    $msg="thanx :)"; //message to post
    $checksum="358768";
    
    $curlPost = "msg=$msg&post=newreply&format=quick&quickmode=1&topic value=14471405&forum value=169&checksum value=$checksum&caller=$url";
    $ch1 = curl_init();
    
    curl_setopt($ch1, CURLOPT_URL, $url;
    curl_setopt($ch1, CURLOPT_HEADER, 1);
    curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');  
    curl_setopt($ch1, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch1, CURLOPT_COOKIEFILE, 'cookie.txt'); //saved cookies
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch1, CURLOPT_POST, 1);
    curl_setopt($ch1, CURLOPT_POSTFIELDS, $curlPost);
    $data = curl_exec($ch1);
    curl_close($ch1); 
    PHP:


    here is the form of the site (java script code):

    function quickreplyform()
    {
    if (memberID > 0)
    	{
    	document.write("<tr>\
    	[COLOR="Red"]<form name=quickreply action=\""+link+"&t="+ topicID +"\" method=post>\[/COLOR]
    	<td bgcolor=white valign=top align=center><br>\
    	<img src="+fileURL+"icon.aspx?m=reply_topic><br><br><font color=red>\n\
    	ÃÖÝ <br>ÑÏ ÓÑíÚ\n");
    
    	document.write("</td><td bgcolor=white colspan=3 width=100% valign=top align=center>\
    	[COLOR="Red"]<textarea name=msg style=\"width:100%;height:150;"+memberFormat+"\"></textarea>\[/COLOR]
    	[COLOR="Red"]<input type=button onclick='submitQuickReplyForm(1)' value=\"ÃÖÝ ÇáÑÏ ááãæÖæÚ\">");
    [/COLOR]
    
    	document.write([COLOR="Red"]"<input type=hidden name=post value=newreply>\
    	<input type=hidden name=format value=quick>\
    	<input type=hidden name=quickmode value=1>\
    	<input type=hidden name=topic value="+topicID+">\
    	<input type=hidden name=forum value="+forum_id+">\
    	<input type=hidden name=checksum value="+ucs+">\
    	<input type=hidden name=caller value=\""+escape(document.location)+"\">\[/COLOR]
    	</td></form></tr>");
    	}
    }
    
    function submitQuickReplyForm(mode)
    {
    var x = quickreply.msg.value;
    
    while ((x.substring(0,1) == ' ') || (x.substring(0,1) == '\r') || (x.substring(0,1) == '\n') || (x.substring(0,1) == '\t'))
    	x = x.substring(1);
    
    quickreply.msg.value = x;
    
    quickreply.quickmode.value = mode;
    
    if (quickreply.msg.value.length < 3) return;
    else
    	{
    
    	if (mode == 2)	if (!confirm(msg_confirm_lock_topic))	return;
    
    	quickreply.submit();
    	}
    }
    PHP:
    i've highlighted the posting fields...to make things more clear

    anyone?
    thanx in advance :)
     
    linkinpark2014, Jan 29, 2009 IP
  2. darkmessiah

    darkmessiah Peon

    Messages:
    500
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    this is just a guess because you didn't say what the error is, but can you post with curl to a javascript form?

    Looks like you have spaces in the post variable names?! is that valid?
     
    darkmessiah, Jan 29, 2009 IP
  3. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well 1stly, the form is not submitting anything this is the error..
    2ndly I want to directly submit the values without passing the values into js function..

    3rdly, what shall i put inside the spaces??
     
    linkinpark2014, Jan 29, 2009 IP
  4. darkmessiah

    darkmessiah Peon

    Messages:
    500
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    2ndly part could be causing your 1stly problem.

    3rdly part, get rid of the spaces. make topic value, topicvalue

    see what happens.
     
    darkmessiah, Jan 29, 2009 IP
  5. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i have corrected the values here is the fixed version:
    $curlPost = "msg=$msg&post=newreply&format=quick&quickmode=1&topic=$grabed_topics&forum=169&checksum=$checksum&caller=$topic_url";
    PHP:
    but still nothing..
    its not posting
     
    linkinpark2014, Jan 29, 2009 IP
  6. darkmessiah

    darkmessiah Peon

    Messages:
    500
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    on the page you are posting to.. see if this value is set or has anything in it, $_POST['msg'] put that at the top of your php script.. if you see anything, then you know your curl routine is working..

    Also, you can echo something from your script so that $data ends up holding a value.

    In fact, after you close your curl handle, do an echo on $data and see whats being returned.
     
    darkmessiah, Jan 29, 2009 IP
  7. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    same same, im getting nothing and there is no sign of anything...
     
    linkinpark2014, Jan 29, 2009 IP
  8. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    okay thanx every1 for help...
    i have fixed the problem...
    now i can post..
     
    linkinpark2014, Jan 29, 2009 IP
  9. darkmessiah

    darkmessiah Peon

    Messages:
    500
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #9
    so what was the issue?
     
    darkmessiah, Jan 29, 2009 IP
  10. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    just added:

    $curlPost = "msg=$msg&post=newreply&format=quick&quickmode=1&topic=$grabed_topics&forum=169&checksum=$checksum&caller=$topic_url&submit=Submit";

    and i corrected the curl link...thats all :D
     
    linkinpark2014, Jan 29, 2009 IP