...

View Full Version : Problems with FSockOpen



spyke01
03-07-2010, 10:32 PM
Hey Guys,
I'm trying to build a function to pull data from a remote url using variables however i'm running into some issues. The URL i'm pulling from in this example is http://www.fasttracksites.com/versions/versionChecker.php?app=fts_clms&type=1 but my function is pulling extra data that doesn't exist on the page.

Here is the result of the function:


a 2.10.03.05 0


This is the actual data:


2.10.03.05


Here is the actual function:


function returnRemoteFilePost($host, $directory, $filename, $urlVariablesArray = array()) {
$errstr = $errno = $returnVar = $file_info = $urlVariables = $result = "";

if ($fsock = @fsockopen($host, 80, $errno, $errstr, 10)) {
$get_info = false;

$urlVariables = array();
while(list($n,$v) = each($urlVariablesArray)){
$urlVariables[] = "$n=$v";
}
$urlVariables = implode('&', $urlVariables);

$header = "POST /" . $directory . "/" . $filename . " HTTP/1.1\r\n";
$header .= "Host: " . $host . "\r\n";
$header .= "content-type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($urlVariables) . "\r\n";
$header .= "Connection: close\r\n\r\n";
$header .= $urlVariables . "\r\n";
echo nl2br($header);
@fputs($fsock, $header);

while (!@feof($fsock)) {
$result .= fgets($fsock); //get the results
}
@fclose($fsock);
}
else {
if ($errstr) {
$errstr = utf8_convert_message($errstr);
}
else {
$errstr = "FSock Error";
}
}
// split the result header from the content
$result = explode("\r\n\r\n", $result, 2);

$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
echo "<strong>" . $content . "</strong>";

$returnVar = ($errstr == "") ? $content : $errstr;

return $returnVar;
}


Here is an example call:


echo returnRemoteFilePost("www.fasttracksites.com", "versions", "versionChecker.php", array('app' => $A_Name, 'type' => 1));



Can anyone tell me why i'm seeing extra data?

SOLVED: I plan on using either the code at http://codingforums.com/showthread.php?t=147061 or cURL to solve this



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum