Solved

Form Id with PHP + cURL

Posted on 2004-10-12
12
501 Views
Last Modified: 2012-06-27
Hi,

I hope someone can help me with a small info.


I 'm trying to post following form data using cURL to IIS server (not under my control), but remote site is obviusely checking »form id«.
Question is how to send »form id« via cURL?

HTML
<form  id=admin action="www.somesite.com/test.asp" method="POST">
<input type="hidden" name="var1" value="1">
<input type="hidden" name="var2" value="2">
<input type="hidden" name="var3" value="3">
    <input type="submit" name="button" value="push">
</form>

PHP + cURL
<?
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL," www.somesite.com/test.asp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "var1=1&var2=2&var3=3id=admin");

curl_exec ($ch);
curl_close ($ch);
?>


Any Ideas?

Thx, Robert
0
Comment
Question by:Whisky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
12 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12286075
What is missing in your postfield is the button=push
try this:

curl_setopt($ch, CURLOPT_POSTFIELDS,
            "var1=1&var2=2&var3=3&button=push");
0
 

Author Comment

by:Whisky
ID: 12286230
Hi hernst42,

I tried that option too, but no luck.
My wild guess would be that remote site is using "Request.Form("id")" method for checking
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12286364
I have used you example code and looked into the transmitted HTTP-protocol there where only those 4 variables sent to the webserver:

var1=1&var2=2&var3=3&button=push
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:frugle
ID: 12286565
Request.Form("id")

would return "admin" if you also had <input type="hidden" name="id" value="admin">

your wild guess is quite inaccurate. <form id= ID is used by Javascript in validation, e.g. document.id.submit(); to call the submit routine on that particular form.

The server is more likely to be picking up the referring page and throwing your input out.

Mike
0
 

Author Comment

by:Whisky
ID: 12286719
My HTML example code IS working,

and PHP+cURL is NOT, I'm not very familiar with .asp so my guess is / can be inaccurate.

How to solve the problem is basic question ... any more ideas?
0
 
LVL 10

Expert Comment

by:frugle
ID: 12286779
var1=1&var2=2&var3=3id=admin

should be

var1=1&var2=2&var3=3&id=admin
                                   ^ note
Mike
0
 

Author Comment

by:Whisky
ID: 12288213
Tried ... var1=1&var2=2&var3=3&id=admin ... NOT working

I'm posting to .asp page (which structure or code I have not seen), so I can not say how it functions or what it checks, but never the less HTML example (resides on my server so the referer can not be a problem) which I posted a few posts up ... is working, So only difference between HTML example and cURL is "form id", also if I throw "form id" out, HTML example does not work anymore.
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 12288560
You might try a network sniffer which log the packets send by your browser to that asp-page and see which information is posted to the asp page, then check what you curl-request is send and what might be missing. (For Windows I don't know such a tool. On Unix use ethereal e.g.)
0
 
LVL 10

Assisted Solution

by:frugle
frugle earned 250 total points
ID: 12288722
http://www.htmlhelp.com/reference/html40/attrs.html#id

The ID attribute uniquely identifies an element within a document. To my knowledge it is not passed by the browser.


The problem is more likely to be cURL, and the fact that it sends data as application/x-www-form-urlencoded

Is it possible to give more information on the server that you are communicating with and the variables you are sending?

Mike
0
 
LVL 10

Expert Comment

by:frugle
ID: 12482943
no objections here, though would be nice to know if the questioner actually solved the problem with our advice.

Mike
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question