...

View Full Version : $_POST >> form submit help



JSlime
03-20-2004, 09:47 PM
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:



<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:



<?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

firepages
03-22-2004, 02:52 AM
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
.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum