PHP

Get an XMPP instant message when someone interacts with your website.

Your Website Can Send you XMPP Messages

You can recieve an instant message whenever someone interacts with your website.

You must enable shell_exec in php. It usually is enabled, but check in the configuration file php.ini:

# Where is my php.ini file?
find /etc -name php.ini
/etc/php/7.0/apache2/php.ini
/etc/php/7.0/cli/php.ini

# It must be the one in the apache2 directory. Is shell_exec enabled?
grep disable_functions /etc/php/7.0/apache2/php.ini
disable_functions = show_source,system,shell_exec,exec
  • Backup the file php.ini.
  • Edit php.ini.
  • Remove shell_exec from disable_functions.
  • Restart apache2 service:
service apache2 restart

Now, in your PHP code, just add the message you want sent to you:

<?php  // COPY AND PASTE THIS CODE EXAMPLE TO GET YOU STARTED
if(!isset($_POST['fname'])){  // IF NOT POSTED, SHOW THE FORM 
?><form method="post">
What is your name? <input type="text" name="fname">
<input type="submit" />
</form><?php }else{ // ELSE THE FORM POSTED
echo 'Your name is ' . $_POST['fname'];
// LOOK AT HOW EASY THIS IS:
$msg='<SMIRK> Someone just sent his first name on the website: '.$_POST['fname'];
shell_exec('/usr/local/bin/monitor.chat.sh "'.$msg.'" 1>/dev/null 2>&1 &');
// DONE! A MESSAGE IS POSTED TO YOUR CHATROOM!
} ?>

When someone uses the form on your website, a message is sent to your chatroom by XMPP.

Some tips for using monitor.chat.sh with PHP

  • 1>/dev/null sends the output into oblivion. /dev/null is a virtual file that doesn’t save anything.
  • 2>&1 sends any warnings or errors into the same output stream as the first, in other words, it goes into oblivion too.
  • the final & just puts the process into the background. Even though monitor.chat.sh finishes in less than a second, it ensures that the script never slows down PHP.
  • <SMIRK> is a shorcode for the ejoji 😏. Review the Emoji page to learn how to include emojis from shortcodes.
Last modified December 1, 2020