Jump to content

For Each Loop and $_POST Variables


lalnfl

Recommended Posts

foreach ($_POST as $key => $value){

 

// Handle escape characters, which depends on setting of magic quotes

 

if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1){

 

$value = urlencode(stripslashes($value));

 

}

 

else {

 

$value = urlencode($value);

 

}

 

$req .= "&$key=$value";

 

}

 

$reg is not returning anything.

Link to comment
https://forums.phpfreaks.com/topic/231550-for-each-loop-and-_post-variables/
Share on other sites

Its for a Paypal Listener, and it says to encode it to send it back.

 

$req = "cmd=_notify-validate";

if (function_exists("get_magic_quotes_gpc")){

$get_magic_quotes_exists = true;

}

foreach ($_POST as $key => $value){

// Handle escape characters, which depends on setting of magic quotes 

if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1){
  		
	$value = urlencode(stripslashes($value)); 	

} 

else {

	$value = urlencode($value); 	

}

$req .= "&$key=$value"; 

}

$ch = curl_init("https://www.sandbox.paypal.com/cgi-bin/webscr");

curl_setopt($ch, CURLOPT_HEADER, "POST /cgi-bin/webscr HTTP/1.0\r\n");
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/x-www-form-urlencoded\r\n");
curl_setopt($ch, CURLOPT_HEADER, "Content-Length: " . strlen($reg) . "\r\n\r\n");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$response = curl_exec($ch);

$http = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

 

Also is the cURL right, in order to send it back to paypal?

OK, if that's what they say to do with it, I guess that's what they need . . .

Try this . . .

if( function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ) {
     $_POST = array_map( 'stripslashes', $_POST );
}
$_POST = array_map( 'urlencode', $_POST );

OK, if that's what they say to do with it, I guess that's what they need . . .

Try this . . .

if( function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ) {
     $_POST = array_map( 'stripslashes', $_POST );
}
$_POST = array_map( 'urlencode', $_POST );

 

Okay I got it to work. Is my cURL stuff right, when I send it back to paypal?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.