I am attempting to mimic a form post or [simulate a form post]
I have a form on my website that sets cookies in the header when the initial form page loads.
I think i a\have the script set up correctly to send the form data.
My problem:
I am trying to figure out how to send the cookie that is set in the header when i
send other form variables via php.
the script that sets the cookies is below:
now b4 i get beat up 4 putting a javascript code in php section:
my php file [zend02.php] is:
the postit2.php file referenced above:
my php code to simulate the form on my website gives the following error when used:
Fatal error: Call to a member function on a non-object in /var/ on line 15
now i was told i am recieving the 'non object error' because sendRequest in the 1st code is returning an array.
how can i have the cookie variable sent with the form?
I have a form on my website that sets cookies in the header when the initial form page loads.
I think i a\have the script set up correctly to send the form data.
My problem:
I am trying to figure out how to send the cookie that is set in the header when i
send other form variables via php.
the script that sets the cookies is below:
Code:
<script type="text/javascript">
function SetCookie(name, value) {
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + (60*60*24*30));
document.cookie = 'serendipity[' + name + ']='+escape(value) + ';expires=' + expire.toGMTString();
}
</script>
now b4 i get beat up 4 putting a javascript code in php section:
my php file [zend02.php] is:
Code:
<?php
require_once "HTTP/Request.php";
include("postit2.php");
$req =& new HTTP_Request("[URL unfurl="true"]http://www.abc.com/userz/mel/ser_admin.php");[/URL]
$response = $req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage();
} else {
print_r($response->getResponseCookies());
}
$data["dbType"] = "mysql";
$data["dbHost"] = "localhost";
$data["dbUser"] = "mem";
$data["dbPass"] = "letmein";
$data["dbName"] = "me";
$result = post_it2($data, " [URL unfurl="true"]http://www.abc.com/userz/mel/ser_admin.php");[/URL]
if (isset($result["errno"])) {
$errno = $result["errno"];
$errstr = $result["errstr"];
echo "<B>Error $errno</B> $errstr";
exit;
} else {
for($i=0;$i< count($result); $i++) echo $result[$i];
}
?>
the postit2.php file referenced above:
Code:
<?php
function post_it2($data, $URL) {
// Strip http:// from the URL if present
$URL = ereg_replace("^[URL unfurl="true"]http://",[/URL] "", $URL);
// Separate into Host and URI
$Host = substr($URL, 0, strpos($URL, "/"));
$URI = strstr($URL, "/");
// Form up the request body
$ReqBody = "";
while (list($key, $val) = each($data)) {
if ($ReqBody) $ReqBody.= "&";
$ReqBody.= $key."=".urlencode($val);
}
$ContentLength = strlen($ReqBody);
// Generate the request header
$ReqHeader =
"POST $URI HTTP/1.0\n".
"Host: $Host\n".
"User-Agent: PostIt\n".
"Content-Type: application/x-[URL unfurl="true"]www-form-urlencoded\n".[/URL]
"Content-Length: $ContentLength\n\n".
"$ReqBody\n";
// echo $ReqHeader;
// Open the connection to the host
$socket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$socket) {
$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket) && $Result[$idx-1] != "0\r\n") {
if (substr($Result[$idx-1], 0, 2) == "0\r\n") echo "The End:".strlen($Result[$idx-1]);
$Result[$idx++] = fgets($socket, 128);
}
return $Result;
}
?>
my php code to simulate the form on my website gives the following error when used:
Fatal error: Call to a member function on a non-object in /var/ on line 15
now i was told i am recieving the 'non object error' because sendRequest in the 1st code is returning an array.
how can i have the cookie variable sent with the form?