How do we include_once an external (outside of Magento 2 code but on the same web server) PHP file?
I added the events.xml and adminuserlogin.php files below, into an already activated and fucntioning admin module, but my attempts to have the Observer call/include the PHP file does nothing. Do you see anything wrong with the code?
The module folder structures and the code are as follows:
/home/abc/public_html/app/code/abcCo/Backend/etc/adminhtml/events.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="backend_auth_user_login_success">
<observer name="backend_activity" instance="abcCo\Backend\Observer\adminuserlogin" />
</event>
</config>
/home/abc/public_html/app/code/abcCo/Backend/Observer/adminuserlogin.php:
<?php
namespace abcCo\Backend\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
class adminuserlogin implements ObserverInterface
{
public function __construct()
{
//Observer initialization code...
//You can use dependency injection to get any class this observer may need.
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
// execute an external php script when I log in.
include_once '/home/abc/public_html/app/code/abcCo/testModule/Controller/Index/login_test.php';
}
}
?>
Thank you.