MyBB Community Forums

Full Version: xmlhttp plugin hook - permission error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If I hook into the xmlhttp, the xmlhttp response returns the admin login page.

define( 'IN_MYBB', 1 );

require_once '../../../admin/global.php';
require_once MYBB_ROOT . '/inc/functions.php';

$plugins->add_hook( 'xmlhttp', 'myadzones_xmlhttp' );

function myadzones_xmlhttp()
{
    global $db, $mybb, $config;

    //update ad clicks or views for banner id
    if( $mybb->input['action'] == 'myadzones_update_stats' && $mybb->request_method == 'post' )
    {
        $query  = $db->query( 'SELECT ' . $mybb->input['mode'] . ' FROM ' . TABLE_PREFIX . 'myadzones_stats WHERE bid=' . $mybb->input['bid'] . ' && zid=' . $mybb->input['zid']);
        $result = $db->fetch_array( $query );

        if( $result )
            $update = $db->query( 'UPDATE ' . TABLE_PREFIX . 'myadzones_stats SET ' . $mybb->input['mode'] . '=' . ( $result[$mybb->input['mode']] + 1 ) . ' WHERE bid=' . $mybb->input['bid'] . ' && zid=' . $mybb->input['zid'] );
    }
}

This is used to update clicks and impressions from ad banners. The banner plugin uses some DOM to add an onlick handler to the banner which is wrapped in a span. Impressions are updated on page load. If I hardcode the conditional into xmlhttp.php or include it in a seperate file and call that file, the request works. I probably left out a necessary step or process here. Any suggestions to make it where mybb sees the request as valid?