SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Nov 23, 2004, 08:31 #1
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; }
-
Nov 23, 2004, 21:07 #2
This is really urgent please help.
-
Nov 24, 2004, 00:26 #3
- 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
-
Nov 24, 2004, 00:31 #4
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 :
Code:$url="https://www.sandbox.paypal.com/cgi-bin/webscr";
Code:$url="http://www.sandbox.paypal.com/cgi-bin/webscr";
Bookmarks