I am using $_POST to post data to a php file. In that php file, I have the following.
$params = array(
'name' => "$fname",
'email' => "$email",
'ad_tracking' => 'test',
'ip_address' => '$_SERVER["REMOTE_ADDR"]',
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
What is the best way to use the $_POST data to define the vales of each keys in the array?
The use of $_SERVER["REMOTE_ADDR"] is also not working as hoped.
POST variables are passed via the super global array
$_POSTin PHP. So in your case, this would technically work:Your code for
$_SERVER["REMOTE_ADDR"]was enclosed in single quotes, which in PHP means a verbatim string (i.e. without variable interpolation).Btw, you should think of input filtering too – http://www.php.net/filter
To give you an example, this would perform input filtering in your current case:
Each value inside
$filteredwill either have a value (valid), beNULL(not present) orfalse(invalid).