Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

This is a discussion on fill in remote form in the Shared & Semi-Dedicated forum
i am trying to cretae a php program to fill in a remote form (two fields; username and password) automatically, and then click the submit ...

  1. #1
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    fill in remote form

    i am trying to cretae a php program to fill in a remote form (two fields; username and password) automatically, and then click the submit button automatically. here is the source code for the remote form:

    <form name="form1" action="http://freesms.breathe.com/sms/v1/prologin.php" method="post">

    <table cellspacing="0" cellpadding="0" width="220" border="0" align="center">


    <tr>
    <td class="maincontent" width="170">phone number</td>
    <td align="left"><input name="phonenumber" size="15"></td>
    </tr>

    <tr>
    <td class="maincontent" width="170">password</td>
    <td align="left"><input type="password" name="password" size="15"></td>
    </tr>

    <tr>
    <td width="170"></td>
    <td><input type="submit" value="login" name="submit"></td>
    </tr>
    </table>


    lets say the password = dave and username = hello

    how can i do this?

    thankyou

  2. #2
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    i think i have a small clue what to do. the following is some code i have tried:
    PHP Code:
    <?
    error_reporting 
    (E_ALL);

    echo 
    "<h2>IP connection</h2>\n";

    $service_port getservbyname ('www''tcp');

    $address gethostbyname ('http://www.domain.com');

    $socket socket_create (AF_INETSOCK_STREAM0);
    if (
    $socket 0) {
       echo 
    "socket_create() failed: reason: " socket_strerror ($socket) . "\n";
    } else {
            echo 
    "OK.\n";
    }

    echo 
    "attempting to connect to '$address' on port '$service_port'...";
    $result socket_connect ($socket$address$service_port);
    if (
    $result 0) {
       echo 
    "socket_connect() failed.\nreason: ($result) " socket_strerror($result) . "\n";
    } else {
               echo 
    "OK.\n";
    }

    $in "HEAD / HTTP/1.0\r\n\r\n";
    $out '';

    echo 
    "sending http head request...";
    socket_write ($socket$instrlen ($in));
    echo 
    "OK.\n\n";

    ECHO 
    "READING respnose:\n\n";
    while (
    $out socket_read ($socket2048)){
                                                  echo 
    $out;
                                                      }
                                                      

                                                      echo 
    "closing socket...";
                                                      
    socket_close ($socket);
                                                      echo 
    "OK.\n\n";
                                                      
    ?>
    which gets header info about a url, although it doesnt work, i get the following message;

    Fatal error: Call to undefined function: socket_create() in c:\wampp1-smart\htdocs\test\socket.php on line 10


    anyone know why this is?

    Also, how can i change this code to submit info to a form as above?

  3. #3
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    The easiest way to do this is to "shell out" in PHP to a program called curl. curl is kind of like a non-interactive web browser. It can submit forms and retrieve files over HTTP, FTP, and several other protocols.

    PHP Code:
    $res = `curl [url]http://freesms.breathe.com/sms/v1/prologin.php[/url] -d username=hello -d password=hello -d submit=login`; 
    When you run the script, curl will submit the form to the host site. Whatever the host sends in return will be collected in the $res variable.

    Note that the command is wrapped in backticks (`, the quote character you get when you hit the tilde key without holding down shift.

    --Jason
    Last edited by jason; 07-07-2003 at 12:53 PM.
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  4. #4
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    once again - thanks for the reply it's greatly appreciated.

    i'll let you know how i get on. I am doing this so that when a customer buys from my site, i'll get an sms message on my mobile to let me know.

  5. #5
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    in the code, the secong url bit http://, seems to be cancelling out the rest of the line;

    rologin.php" target="_blank">http://freesms.breathe.com/sms/v1/prologin.php</a> -d username=07745341975 -d password=elvispelvis -d submit=login`;

    do i have to put single quotes ' ' arround the url?

    also, i tried to echo $res but nothing came out. how can i know the $res contains data?

    thanks

    also, does jaguarpc have the curl package already installed?
    Last edited by davidstummer; 07-08-2003 at 01:50 PM.

  6. #6
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Curl should be installed on your server at /usr/bin/curl, I believe.

    You may need to escape the slashes with backslashes:

    http:\/\/

    Your actual code should look something like
    <?
    $res = `curl http:\/\/fresms....`;
    ?>

    It would go into the code of your shopping cart script somewhere after the user submits their order. It shouldn't have any <a> tags or anything like that wrapped around it. I'm not sure if that's something you did or if the fourms put that in.

    You may need to specify the full path to curl in the command:

    $res = `/usr/bin/curl...`;

    Also, if you are going to pass any variable in to any of the -d arguments to curl, your should run them through urlencode() first:

    PHP Code:
    <?
        $username 
    urlencode($username);
        
    $res = `... -d $username...`;
    ?>
    Good luck.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  7. #7
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74
    i tried looking for the curl file and its path via ftp but i cant find it.

    how can i locate it?

    thanks

  8. #8
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    You won't find curl with FTP. FTP only shows you files that are stored within your home directory. Curl is stored in one of the system-wide directories.

    The easiest way to find where a program resides is to start up an SSH session and type the command

    which programname

    in this case

    which curl

    The which program searches all of the directories where the system knows to look for programs and returns a list of programs it found that match what you're seeking. In the cse of curl (on silicon, at least), it returns /usr/bin/curl, confirming my guess from earlier.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  9. #9
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    i did the SSH thing and the path is the same as yours. to confirm, php info shows that curl is enabled. But whenever i try, it doesn't seem to connect. This is the first piece of code i tried:
    PHP Code:
    <?
    $res 
    = `/usr/bin/curl <a href="http://freesms.breathe.com/sms/v1/prologin.php" target="_blank">http:\/\/freesms.breathe.com/sms/v1/prologin.php</a> -d phonenumber=6666666666 -d password=eeeeeeeeee -d submit=login`;
    echo 
    $res;
    ?>
    nothing was echoed. the second piece of code returned the default text indicating it too was not working:

    PHP Code:
    <? 
    switch($_REQUEST['cmd']){ 
        default: 
            echo 
    "cannot perform operation";
        break;

        case 
    "post":
            
    $postfields = array();
            
    $postfields[] = array("phonenumber"$_POST['66666666666']);
            
    $postfields[] = array("password"$_POST['eeeeeeeeeeee']);
            
    $postfields[] = array("login"$_POST['submit']);

            foreach(
    $postfields as $subarray) { 
                 list(
    $foo$bar) = $subarray
                 
    $bar urlencode($bar); 
                 
    $postedfields[]  = "$foo=$bar";
            }

            
    $urlstring join("\n"$postedfields);
            
    $urlstring ereg_replace("\n""&"$urlstring); 
             echo 
    $urlstring;

            
    $ch curl_init("http://freesms.breathe.com/sms/v1/prologin.php");
            
    curl_setopt($chCURLOPT_HEADER0);
            
    curl_setopt($chCURLOPT_POST1);
            
    curl_setopt($chCURLOPT_POSTFIELDS$urlstring);
            
    curl_setopt($chCURLOPT_FOLLOWLOCATION0);
            
    curl_setopt($chCURLOPT_REFERER"http://www.mysite.com/payment_form.html");
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1); 
            
    curl_getinfo($chCURLINFO_HTTP_CODE);
            
    $data curl_exec($ch);
            
    curl_close($ch);

        break;
    }

    ?>
    does anyone know why this is?

  10. #10
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    I tried to grab the contents of the URL that you're using with curl (I just didn't pass any variables), and it didn't work for me either. I also tried grabbing jaguarpc.com, and that worked. That leads me to believe that breathe.com may somehow be blocking people from linking directly into their site like you're trying to do. There are some things you can try to do to get around this, such as forcing cURL to use a specific HTTP_USER_AGENT or HTTP_REFERER header, or sending certain cookies. There are many things that a site operator can do to restrict access. It can often be circumvented, but it takes a little time to figure out what they are using behind the scenes to make the restriction happen.

    Your second example has two problems. Its not giving the "cannot perform operation" message because curl isn't working, its doing it because you're telling it to do that. The line

    switch($_REQUEST['cmd']){

    says look at the value of the the submitted form field "cmd" and execute the chunk of code based on its value. If you aren't sending a "cmd" value of "post" to the form then the curl call will never be executed. Futher, the way switch statements work is that PHP finds a looks for a match to the value in the switch() statement in your case statements. When it finds one it starts running the code until it comes to either a break statement or the end of the switch code block. But, if it finds a default statement before making a match, it starts execution then. Generally you make the default case the last thing in the block. Since you have it first, you are telling PHP to always execute that, and since it exits the block when it comes to the break statement, the "post" case never executes, even if you submit the required "cmd" value.

    I'm not sure how it works in the UK, but for most (if not all) US cell phones, there is an email address attached to the phone that can be used to send SMS messages. For example, I can email my phone number @messaging.sprintpcs.com to send an SMS to my phone. In a script, all I'd ahve to do is use PHP's mail() function, which is far less complicated. Web based SMS tools are good for sending messages when you either don't know the service provider of someone's phone (as this example illustrates, or when you as the sender are sending the message interactively by typing into the web form, such as with this example. When you are trying to automate it, there are usually better ways, such as with email.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  11. #11
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    i have managed to get the login page to show using:

    PHP Code:
    <?php 
    $ch 
    curl_init ("http://freesms.breathe.com/sms/v1/");
    $fp fopen ("prologin.php""w");
    curl_setopt ($chCURLOPT_FILE$fp);
    curl_setopt ($chCURLOPT_HEADER0);
    curl_exec ($ch);
     
    curl_close ($ch);
     
    fclose ($fp);
     
    ?>
    how can i add the post variables such as username and password to this?

    thanks

  12. #12
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Not tested, but I think you'd want to use something like this:

    PHP Code:
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_POSTFIELDS,  "username=abcdefg&password=1234567"); 
    I've only used the command line version of curl, I've never tried the libcurl functions that are built into PHP, so I'm not sure if what I'm suggesting will work or not. You might have to play with it a little bit...

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  13. #13
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    it doesnt seem to be working. is there any way i could get a look at the sites php code before it gets turned into html?

  14. #14
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    No, there isn't. PHP is designed to be run on the server where it generates output as HTML (usually). If it were possible to get a peak at the code running on a site we'd have HUGE! security risks all over the place. Sites take great care to make sure things like that can't happen...

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  15. #15
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    re

    i have noticed that after phonenumber and password are submitted, it gets sent to prologin.php, and then wel.php, where it displays the page. does this mean the prologin.php could change the values in any way? Is there anyway i could try this using sockets?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •