tags:

views:

87

answers:

2

I have problem i`m trying post data with php and cURL but that not working.

How should looks correctly code if form is secure by random session id in input value, and have pieces of posting (stage )

            <form name='p' method='post' action='/pl/Register.php'>
        <input type='hidden' name='sid' value='wa12891300kv1283056988qwpvkdaazzipdgouxd'>
        <input type='hidden' name='stage' value='20'> <!-- this value change when post some "values" -->
        <input type='hidden' name='addressline1' value=''>
        <input type='hidden' name='addressline2' value=''>
        <input type='hidden' name='addressline3' value=''>

        <input type='hidden' name='addressline4' value=''>
        <input type='hidden' name='postcode' value=''>
        <input type='hidden' name='bankname' value=''>
        <input type='hidden' name='sortcode' value=''>
        <input type='hidden' name='accountname' value=''>
        <input type='hidden' name='accountnumber' value=''>
        <input type='hidden' name='cardname' value=''>
        <input type='hidden' name='cardtype' value=''>
        <input type='hidden' name='cardnumber' value=''>

        <input type='hidden' name='startmonth' value=''>
        <input type='hidden' name='startyear' value=''>
        <input type='hidden' name='expirymonth' value=''>
        <input type='hidden' name='expiryyear' value=''>
        <input type='hidden' name='cardsecurity' value=''>
        <input type='hidden' name='cardissue' value=''>
        <input type='hidden' name='delname' value=''>
        <input type='hidden' name='deladdressline1' value=''>
        <input type='hidden' name='deladdressline2' value=''>

        <input type='hidden' name='deladdressline3' value=''>
        <input type='hidden' name='deladdressline4' value=''>
        <input type='hidden' name='delpostcode' value=''>
        <input type='hidden' name='delphone' value=''>
        <input type='hidden' name='sponsor' value=''>
        <input type='hidden' name='uid' value=''>
        <input type='hidden' name='password' value=''>
        <input type='hidden' name='password1' value=''>
        <input type='hidden' name='password2' value=''>

        <input type='hidden' name='terms1' value='0'>
        <input type='hidden' name='terms2' value='0'>

any help will be welcome.

A: 

You are showing us an HTML form. Your PHP script is /pl/Register.php? What exactly are you trying to post, from where, and to where?

PHP runs server-side, not client-side. PHP doesn't run in the browser, so you cannot post a form with PHP from the browser. You can only do that with Javascript... or better yet, just a submit button will do in this case.

Brad
I`m trying post personal data (like date of born, home address etc) Unfortunately I don`t know what exactly php looks like on original site http://www.betterware.eu/pl/Register.php but my code is http://pastebin.com/LPHVuxKB
ramadan
A: 

There are two parts:

  • Obtain the value of sid.
  • Send the post request with the sid value and the rest of your data.

First we get sid. I don't know enough about what happens when you request the form, but if it is just a random number assigned every time you go to the page, then you can fetch the page in your php script and search for its value. We can do that simply using file_get_contents and a regex:

    $remote_site = file_get_contents("http://example.com/pl/Register.php");
    if (preg_match('/name=\'sid\' value=\'(.+?)\'/', $remote_site, $match)) {
            $sid = $match[1];
    } else {
            exit('failed to find sid');
    }

Now we just need to send the post request using cURL. You need to extract all the data out of the form you want to submit.

I suggest putting it in an associative array:

    $post_data = array(
            'sid' => $sid,
            'stage' => '...',
    );

I'll leave it up to you to fill in the rest.

In order to post it you want to send a post request with cURL, using CURLOPT_POST and CURLOPT_POSTFIELDS as follows:

    $ch = curl_init("http://example.com/pl/Register.php");
    curl_setopt($ch, CURLOPT_POST, true); // tell cURL we are doing a post request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // we pass in our data as an array here
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // this stops the output from being printed directly
    $response = curl_exec($ch);

You can then read $response to see the results of the request. *

leafo
Like i`m wrote bellow my code is here, http://pastebin.com/LPHVuxKBProblem to get "sid" value i have remove, but now i have problem with posting this. That is hard to me because in stage 90 i must "get response" and get content of <big>PL-42XXX</big> value and post it too. maybe if You see form at http://www.betterware.eu/pl/Register.php u can simple say somethings new. But i will try catch response form curl_exec($ch); and preg_match for get uid value
ramadan