Method Community

 

Posting using cURL (PHP)

Last post 12-20-2010 1:36 PM by Method_Victor. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-19-2010 1:04 PM

    Posting using cURL (PHP)

    Hi,

    we're attempting to post the web-to-lead form using a PHP script as other processes happen on our server before the form should be submitted.

     

    Having difficulty getting it to work. The URL and settings seem correct, but I'm guessing since the target url is "timezonerouter.aspx?url..." that the redirect to "url" isn't happening and therefore the actual form is not submitted.  We tried cURLing directly to the url (bypassing timezonerouter) but that didn't work either.

     

    Any recommendation?

     

    Thanks,

    Yoav

     

  • 12-20-2010 8:29 AM In reply to

    Re: Posting using cURL (PHP)

    Hi Yoav,

    Can you tell me what error messages are you getting and what exactly doesn't work in your process of submitting the form? When you've used cURL just to https://www.methodintegration.com/MethodWebForms/submit.aspx, did you get a different error?

    I am not too familiar with cURL and PHP, but this is what you pretty much need to do (based on example at http://ca2.php.net/manual/en/curl.examples.php and my understanding of PHP)

    <?php
    $ch
    = curl_init("
    https://www.methodintegration.com/method/timezonerouter.aspx?url=https://www.methodintegration.com/MethodWebForms/submit.aspx");
    $encoded = '';
    // include POST variables; Don't forget hidden variables.
    foreach($_POST as $name => $value) {
     
    $encoded .= urlencode($name).'='.urlencode($value).'&';
    }
    // chop off last ampersand
    $encoded = substr($encoded, 0, strlen($encoded)-1);
    curl_setopt($ch, CURLOPT_POSTFIELDS$encoded);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //It needs to know the referrer, therefore it will be able to validate the form
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_exec($ch);
    curl_close($ch);
    ?>

    So this is overall process that is supposed to happen as a result of this script:

    1. Redirect user to page https://www.methodintegration.com/method/timezonerouter.aspx forwarding all of the information user has entered as a POST parameters and forwarding the header information.

    2. timezonerouter.aspx will redirect user to page https://www.methodintegration.com/MethodWebForms/submit.aspx?TzId=Eastern Standard Time adding a timezone parameter at the end of the URL

    3. Submit.aspx page will do it's magic with the parameters that were passed in, submitting them to Method. Then, it will redirect user to page user had provided or if user did not specify a page, will redirect user to the original page from which person initially came from.

    Thank you

    Victor

  • 12-20-2010 10:38 AM In reply to

    Re: Posting using cURL (PHP)

    Victor,

    I did submit to the form and I got the following response:


    <!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 id="Head1"><title>
    Timezone Lookup
    </title>
    <script type="text/javascript" src="Javascript/TimezoneLookup.js?rnd=1110"></script>
    <script type="text/javascript">
    function GetScreenSize(ScreenResolutionWidth, ScreenResolutionHeight) {
    document.getElementById(ScreenResolutionWidth).value = screen.width;
    document.getElementById(ScreenResolutionHeight).value = screen.height;
    document.forms["form1"].submit();
    }
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="TimeZoneRouter.aspx" id="form1">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODIwNzAzMTY2DxYGHgpQb3N0UGFyYW1zMosKAAEAAAD/////AQAAAAAAAAAMAgAAAE1TeXN0ZW0uV2ViLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49YjAzZjVmN2YxMWQ1MGEzYQUBAAAAHlN5c3RlbS5XZWIuSHR0cFZhbHVlQ29sbGVjdGlvbgYAAAAIUmVhZE9ubHkLS2V5Q29tcGFyZXIFQ291bnQES2V5cwZWYWx1ZXMHVmVyc2lvbgADAAYFAAEWU3lzdGVtLk9yZGluYWxDb21wYXJlcggIAgAAAAEJAwAAAA0AAAAJBAAAAAkFAAAADgAAAAQDAAAAFlN5c3RlbS5PcmRpbmFsQ29tcGFyZXIBAAAAC19pZ25vcmVDYXNlAAEBEQQAAAANAAAABgYAAAADb2lkBgcAAAAGcmV0VVJMBggAAAAIZm9ybU5hbWUGCQAAAA9GaXJzdE5hbWVfU3RlcDIGCgAAAA5MYXN0TmFtZV9TdGVwM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AAABAAAABjUAAAAGR29vZ2xlECkAAAABAAAABjYAAAAKcHVibGlzaGVycxAqAAAAAQAAAAY3AAAABG5vbmUQKwAAAAEAAAAGOAAAAANVU0QQLAAAAAEAAAAGOQAAAAEwCx4JR2V0UGFyYW1zMuADAAEAAAD/////AQAAAAAAAAAMAgAAAE1TeXN0ZW0uV2ViLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49YjAzZjVmN2YxMWQ1MGEzYQUBAAAAHlN5c3RlbS5XZWIuSHR0cFZhbHVlQ29sbGVjdGlvbgYAAAAIUmVhZE9ubHkLS2V5Q29tcGFyZXIFQ291bnQES2V5cwZWYWx1ZXMHVmVyc2lvbgADAAYFAAEWU3lzdGVtLk9yZGluYWxDb21wYXJlcggIAgAAAAEJAwAAAAEAAAAJBAAAAAkFAAAAAgAAAAQDAAAAFlN5c3RlbS5PcmRpbmFsQ29tcGFyZXIBAAAAC19pZ25vcmVDYXNlAAEBEQQAAAABAAAABgYAAAADdXJsEAUAAAABAAAACQcAAAAEBwAAABxTeXN0ZW0uQ29sbGVjdGlvbnMuQXJyYXlMaXN0AwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24FAAAICAkIAAAAAQAAAAEAAAAQCAAAAAEAAAAGCQAAADxodHRwczovL3d3dy5tZXRob2RpbnRlZ3JhdGlvbi5jb20vTWV0aG9kV2ViRm9ybXMvc3VibWl0LmFzcHgLHgtVcmxSZWZlcnJlcmRkZCWqQB3srp96sUajNBQfLWtdtGEH" />
            
    <input type="hidden" name="hdnDay" id="hdnDay" />
    <input type="hidden" name="hdnMonth" id="hdnMonth" />
    <input type="hidden" name="hdnYear" id="hdnYear" />
    <input type="hidden" name="hdnHour" id="hdnHour" />
    <input type="hidden" name="hdnMin" id="hdnMin" />
    <input type="hidden" name="hdnSec" id="hdnSec" />
    <input type="hidden" name="hdnDayStart" id="hdnDayStart" />
    <input type="hidden" name="hdnMonthStart" id="hdnMonthStart" />
            <input type="hidden" name="hdnYearStart" id="hdnYearStart" />
    <input type="hidden" name="hdnHourStart" id="hdnHourStart" />
    <input type="hidden" name="hdnMinStart" id="hdnMinStart" />
    <input type="hidden" name="hdnSecStart" id="hdnSecStart" />
    <input type="hidden" name="hdnDayEnd" id="hdnDayEnd" />
    <input type="hidden" name="hdnMonthEnd" id="hdnMonthEnd" />
    <input type="hidden" name="hdnYearEnd" id="hdnYearEnd" />
    <input type="hidden" name="hdnHourEnd" id="hdnHourEnd" />
    <input type="hidden" name="hdnMinEnd" id="hdnMinEnd" />
            <input type="hidden" name="hdnSecEnd" id="hdnSecEnd" />
    <input type="hidden" name="hdnCurrDate" id="hdnCurrDate" />
    <input type="hidden" name="hdnCurrTZ" id="hdnCurrTZ" />
    <input type="hidden" name="hdnCurrHem" id="hdnCurrHem" />
    <input type="hidden" name="hdnIsDaylightSavingTime" id="hdnIsDaylightSavingTime" value="false" />
    <input type="hidden" name="hdnTzId" id="hdnTzId" />
    <input type="hidden" name="hdnScreenResolutionWidth" id="hdnScreenResolutionWidth" />
    <input type="hidden" name="hdnScreenResolutionHeight" id="hdnScreenResolutionHeight" />
    <input type="hidden" name="hdnCurrDsOffset" id="hdnCurrDsOffset" />
        
    <script type="text/javascript"> FindClientsTimzoneId('hdnCurrDate','hdnCurrTZ','hdnCurrDsOffset','hdnCurrHem','hdnDay','hdnMonth','hdnYear','hdnHour','hdnMin','hdnSec','hdnDayStart','hdnMonthStart','hdnYearStart','hdnHourStart','hdnMinStart','hdnSecStart','hdnDayEnd','hdnMonthEnd','hdnYearEnd','hdnHourEnd','hdnMinEnd','hdnSecEnd','hdnIsDaylightSavingTime'); GetScreenSize( 'hdnScreenResolutionWidth','hdnScreenResolutionHeight'); </script></form>
    </body>
    </html>
    1

    Please notice the 1 at the bottom of the response. Is this the correct behavior? What type of responses we get in case of  success or error scenarios?

    Thanks.

    Hamid

  • 12-20-2010 12:02 PM In reply to

    Re: Posting using cURL (PHP)

    Hi Hamid,

    First of all I am not sure where "1" came from, since if you will go to https://methodintegration.com/method/TimeZoneRouter.aspx and look at the source code, you will not find this number. It might have came from your PHP code.

    Second of all, what you've got as a response is a basic TimeZoneRouter.aspx html, where our serverside code was not executed. My guess is that the cURL function which you are using is simply retrieving the HTML, instead of redirecting to the page and allowing the server side and javascript code to run. Unless you actually allow our code to run, instead of simply retrieving html from our web page, you will not be to submit the form.

    Thank you

    Victor

  • 12-20-2010 12:23 PM In reply to

    Re: Posting using cURL (PHP)

    Victor,

    Is there a way that we can directly post to the submit page instead of relying on a javascript code execution from the TimeZoneRouter.aspx page?

    Hamid

  • 12-20-2010 1:36 PM In reply to

    Re: Posting using cURL (PHP)

    Hamid,

    As I see it, the problem here is that serverside code is not executing (because of cURL). I don't think javascript is a source of the problem you are experiencing. However, to exclude the timezonerouter altogether (as well as a possible Javascript issue) you may do the following:

    Redirect to https://www.methodintegration.com/MethodWebForms/submit.aspx instead of https://www.methodintegration.com/method/timezonerouter.aspx?url=https://www.methodintegration.com/MethodWebForms/submit.aspx. The negative side effect of that, is if you are expecting any dates to be inserted into Method, then all of them will be entered in the "Easter Standard Time" timezone. If you know that all of your clients are from your timezone, that is different than "Easter Standard Time", then you can go to browser and type in https://methodintegration.com/method/timezonerouter.aspx?url=https://www.google.com. As a result you should get a message like following "The request method POST is inappropriate for the URL /?tzId=Eastern%20Standard%20Time&ScreenResolutionWidth=1440&ScreenResolutionHeight=900. ". Then you simply append the tzID parameter to url like following "https://www.methodintegration.com/MethodWebForms/submit.aspx?tzId=Eastern%20Standard%20Time".

    I don't think the above solution will solve your problem, since I don't think that Javascript caused the problems you were experiencing, but you can try. By the way, why do you insist on using cURL instead of simply having a form submit action?

    Thank you

    Victor

Page 1 of 1 (6 items)