Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_POST >> form submit help

    Hello everyone, l've recently stumbled upon this script, and l wanted to know what l would need to do to adapt it to submit a form such as the following:

    Code:
    <form method=POST action=http://www.server1.com/script1.php>
    
    <input type="text" name="name" size="10">
    
    <input type="password" name="password" size="8">
    
    <input type="submit" value="submit">
    </form>
    Here's the script:

    Code:
    <?php
    
          function HTTP_Post($URL,$data, $referrer="http://myreferrer.com") {
    
            // parsing the given URL
            $URL_Info=parse_url($URL);
    
            // Building referrer
            if($referrer=="") // if not given use this script as referrer
              $referrer=$_SERVER["SCRIPT_URI"];
    
            // making string from $data 
            foreach($data as $key=>$value)
              $values[]="$key=".urlencode($value);
            $data_string=implode("&",$values);
          
            // Find out which port is needed - if not given use standard (=80)
            if(!isset($URL_Info["port"]))
              $URL_Info["port"]=80;
      
    
            // building POST-request:
            $request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
            $request.="Host: ".$URL_Info["host"]."\n";
            $request.="Referer: $referer\n";
            $request.="Content-type: application/x-www-form-urlencoded\n";
            $request.="Content-length: ".strlen($data_string)."\n";
            $request.="Connection: close\n";
            $request.="\n";
            $request.=$data_string."\n";
    
    
    
            $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
            fputs($fp, $request);
            while(!feof($fp)) {
                $result .= fgets($fp, 128);
            }
            fclose($fp);
    
            return $result;
          }
    
          $output1=HTTP_Post("http://www.server1.com/script1.php",$_POST);
          ?>
    How would l get the script to input the name, and password variables? what part of the script needs to be edited to have it post the form to http://www.server1.com/script1.php?

    Any break downs, or explanations of the script would be greatly appreciated. Thanks for your time, and your help.

    ~JSlime

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    the function sends whatever data you pass in your form ,so you just need to get the path right..

    $output1=HTTP_Post("http://www.domain.com/page_I_want_to_post_to.htm",$_POST);
    echo $output1;

    now how the page you post to validates the data you are sending for login is unknown here, so not a clue if it would work or not
    .
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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