SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fsockopen() returning a weird error

    Hi.
    I'm trying to use the fscockopen function to integrate the PayPal IPN for a website. What I'm trying to do is to post some variables back to PayPal's website, and here is the one line that causes the error:

    Code:
    function fsockPost($data) { 
    //$data is simply the $_POST array being passed to the function
    $url="https://www.sandbox.paypal.com/cgi-bin/webscr";
     
    //Parse url 
    $web=parse_url($url); 
    //build post string 
    foreach($data as $i=>$v) { 
    $postdata.= $i . "=" . urlencode($v) . "&"; 
    }
    $postdata.="cmd=_notify-validate";
    //Set the port number
    if($web[scheme] == "https") { $web[port]="443";  $ssl="ssl://"; } else { $web[port]="80"; }  
    //Create paypal connection
    $fp=@fsockopen($ssl . $web[host],$web[port],$errnum,$errstr,30); 
    //Error checking
    if(!$fp) { echo "$errnum: $errstr"; } 
     
    //Post Data
    else { 
     
      fputs($fp, "POST $web[path] HTTP/1.1\r\n"); 
      fputs($fp, "Host: $web[host]\r\n"); 
      fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
      fputs($fp, "Content-length: ".strlen($postdata)."\r\n"); 
      fputs($fp, "Connection: close\r\n\r\n"); 
      fputs($fp, $postdata . "\r\n\r\n"); 
    //loop through the response from the server 
    while(!feof($fp)) { $info[]=@fgets($fp, 1024); } 
    //close fp - we are done with it 
    fclose($fp); 
    //break up results into a string
    $info=implode(",",$info); 
    }
    return $info; 
       }
    This line returns a really weird error..the error number is 0 and the error description is "Success". I don't know if this means an error or if this means success. Could the fsockopen be disabled at my server? What should I do about it?

  2. #2
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is really urgent please help.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    South Africa
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have had problems with fsockopen as well a while ago. Some hosts specifically disable this function for "security" reasons. Try using CURL or the Sockets extension if it is installed on your server

  4. #4
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed the problem.. for anyone else interested, I didn't have SSL installed at my server, therefore opening the SSL port was causing the error. I changed :
    to
    And now it works fine.


Bookmarks

Posting Permissions

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