You are here: Re: php POST « PHP Language « IT news, forums, messages
Re: php POST

Posted by Peter on 03/19/07 20:33

> When encountering problems with an external form, I recommend checking the
> headers your actual browser sents (Fiddler can capture this for MSIE,
> liveHTTPheaders can do this for Firefox). Try to set all headers exactly
> alike in cURL untill it works, and then remove them again one by one to
> see which are actually required.

Sorry I took so long to respond !!
I am playing with it now.

Question.
When I use this to post to an external form, and that external form uses IP
checking, what will the IP be ?
Will it be the IP of the person activating the script (curl.php) ? Or will
it be the IP of the server where the script is running ?


-------------------------------------------------------
Because it was so long ago I kept the full message intact:
-------------------------------------------------------
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:9dc22$4579e572$8259c54a$29129@news2.tudelft.nl...
> -Lost wrote:
>> I would be interested in a static example of this as I cannot reproduce
>> it.
>>
>> Once, I had output. It wound up showing me a (print_r) print fifty or so
>> times before I had to restart the server. The oddest thing is I have
>> gotten mixed results with it delivering my 404 page and even printing
>> then showing 500 internal server.
>
> Quick'n'Dirty cURL example:
> (For these purposes, I've put eveything in localhost/test, any other url
> is offcourse possible).
>
> -----form.php-----------
> <?php
> if(isset($_POST['submit'])){
> echo "<pre>Victory!\n",var_dump($_POST),"</pre>";
> } else {
> ?>
> <form method="post" action ="<?php echo $_SERVER['PHP_SELF'] ?>">
> <input type="text" name="field1"><br />
> <input type="text" name="field2"><br />
> <input type="submit" name="submit" value="submit">
> </form>
> <?php
> }
> ?>
> ------------------------
> -----curl.php-----------
> <?php
> $postarray = array(
> 'submit' => 'submit',
> 'field1' => 'First field',
> 'field2' => 'Second field');
> //change following url to location of your form.php
> $ch = curl_init('http://localhost/test/form.php');
> curl_setopt($ch,CURLOPT_POST,true);
> curl_setopt($ch,CURLOPT_POSTFIELDS,$postarray);
> curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
> print curl_exec($ch);
> ?>
> ------------------------
>
> Keep in mind that in some external forms/server outside your control (or
> on your own server if you've set it), you may need more curl_setopt()'s
> for for instance sessions, enabling redirects, timeout's, user-agent
> headers, authorisation etc...
>
> The only problem I have with posting forms to external servers is now
> those few rare breeds which require an explicitly set variable by
> javascript... Which offcourse is Evil.
>
> Quick example for file-upload:
> ----form.php----------------
> <?php
> if(isset($_POST['submit'])){
> echo "<pre>Victory!\n",var_dump($_POST),"</pre>";
> echo "<pre>Fileinfo:\n",var_dump($_FILES),"</pre>";
> } else {
> ?>
> <form method="post" action ="<?php echo $_SERVER['PHP_SELF'] ?>">
> <input type="text" name="field1"><br />
> <input type="text" name="field2"><br />
> <input type="file" name="file"><br />
> <input type="submit" name="submit" value="submit">
> </form>
> <?php
> }
> ?>
> -----------------------------
> ----curl.php-----------------
> <?php
> $postarray = array(
> 'submit' => 'submit',
> 'field1' => 'First field',
> 'field2' => 'Second field');
>
> // Change following url to location of your form.php
> $ch = curl_init('http://localhost/test/form.php');
>
> // Change following filename to an actual file on
> // your server running curl
>
> // If curl doesn't respond or output is empty, most
> // likely there's a problem getting the file
>
> $filename = dirname(__FILE__).'/files/IMG_0182.JPG';
> $postarray['file'] = '@'.$filename;
>
> curl_setopt($ch,CURLOPT_POST,true);
> curl_setopt($ch,CURLOPT_POSTFIELDS,$postarray);
> curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
> print curl_exec($ch);
> ?>
> -----------------------------
>
> Output of cURL in my case:
> -----------------------------
> <pre>Victory!
> array(3) {
> ["submit"]=>
> string(6) "submit"
> ["field1"]=>
> string(11) "First field"
> ["field2"]=>
> string(12) "Second field"
> }
> </pre><pre>Fileinfo:
> array(1) {
> ["file"]=>
> array(5) {
> ["name"]=>
> string(12) "IMG_0182.JPG"
> ["type"]=>
> string(10) "image/jpeg"
> ["tmp_name"]=>
> string(37) "C:\Program Files\xampp\tmp\php212.tmp"
> ["error"]=>
> int(0)
> ["size"]=>
> int(645836)
> }
> }
> </pre>
> -------------------------------
>
> The main problem in cURL is not the settings & using it, but
> guessing/determening what requirements an outside form has.
>
> When encountering problems with an external form, I recommend checking the
> headers your actual browser sents (Fiddler can capture this for MSIE,
> liveHTTPheaders can do this for Firefox). Try to set all headers exactly
> alike in cURL untill it works, and then remove them again one by one to
> see which are actually required.
> --
> Rik Wasmus
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация