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 1 of 1
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problems with FSockOpen

    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/versio...ts_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:
    PHP Code:
        function returnRemoteFilePost($host$directory$filename$urlVariablesArray = array()) {
            
    $errstr $errno $returnVar $file_info $urlVariables $result "";
        
            if (
    $fsock = @fsockopen($host80$errno$errstr10)) {
                
    $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"$result2);
         
            
    $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:
    PHP Code:
    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
    Last edited by spyke01; 03-08-2010 at 01:32 AM.


 

Posting Permissions

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