tags:

views:

42

answers:

1

Ok so this is driving me insane! I've got a script written that takes user submitted product information from a previous page and sends it to the user's facebook business page via the facebook php sdk.

Here's the php code:

$app_id = "1234567890"; 
$app_secret = "1234567890";
$page_id = "1234567890";
$page_token = "1034921234567890"; 
$store_name = "MyStore.com"; 
$store_url = 'http://www.mystore.com'; 
$cur = '$'; 
$new_message = "New Product!"; 

    $prod_image = $store_url . "/images/" . $_POST['products_image'];
    $price = $products_price;
    $prod_url = $store_url . '/index.php?main_page=product_info&cPath=' . $current_category_id . '&products_id=' . $products_id;
    $prod_name = $_POST['products_name'][1];
    $prod_description = $_POST['products_description'][1];

include_once 'facebook/facebook.php';

$facebook = new Facebook(array(
      'appId'  => $app_id,
      'secret' => $app_secret,
      'cookie' => true, ));

$attachment = array(
'access_token'      =>  $page_token,
'message'           =>  $new_message,
'name'              =>  $prod_name,
'link'              =>  $prod_url,
'caption'           =>  'Price: '.$cur . $price,
'description'       =>  $prod_description,
'picture'           =>  $prod_image
);

Everything sends to facebook fine except on some servers$prod_description aka $_POST['products_description'][1] ends up empty. When a var_dump($_POST['products_description']); is placed on the same line, it comes back with:

array(1) { [1] => string(35) "This is a test product description." }

So I know the information is there and not being overwritten it's just for whatever reason when sent to facebook (with cURL from the include_once file) it doesn't post.

I should also say that this is a Zen Cart mod that is available for download and I while haven't been able to reproduce the error myself (test on 4 different servers) I have had miltiple users add the var_dump and send me the results.

I guess my question is; Is there something (like a ini setting, cURL option, etc) that may vary from server to server that would cause random indexes to empty when sent via cURL and is there something I can do to fix it?

Thanks in advance.

+1  A: 

I think problem is in the way data is passed. You have spaces in the description, that can cause problems...

Try explicitly setting enctype for the form to "application/x-www-form-urlencoded"

<form enctype="application/x-www-form-urlencoded" .... >

You can also try to url_encode the product description before passing it to Facebook.

$prod_description = urlencode($_POST['products_description'][1]);
Alex