How can PHP be used to automatically post messages to a Facebook fan page wall?

To automatically post messages to a Facebook fan page wall using PHP, you can utilize the Facebook Graph API. You will need to obtain an access token for your Facebook app and have the necessary permissions to post on behalf of the fan page. Once you have the access token, you can use the API to make a POST request to the fan page's feed endpoint with the message you want to post.

<?php

$access_token = 'YOUR_ACCESS_TOKEN';
$page_id = 'YOUR_PAGE_ID';
$message = 'Hello from PHP!';

$url = 'https://graph.facebook.com/' . $page_id . '/feed';
$fields = array(
    'message' => $message,
    'access_token' => $access_token
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

echo $result;

?>