MyBB Community Forums

Full Version: Having an error "Cannot modify header information"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am having issues with one of my own plugins. And i have been trying to fix it myself to no avail. Its not occuring on my localhost but for somebody its happening on their website. I cannot figure out what would be wrong with the following code that would cause such an error:

The error:
[Image: error.jpg]

The plugin:

<?php
/**
* Prevent certain member groups from viewing threads. 
* But still be able to view threadlist.
*
* Copyright 2012 Anori
*/

$plugins->add_hook('showthread_start', 'mgcvthreads_block');
$plugins->add_hook('archive_thread_start', 'mgcvthreads_block');
$plugins->add_hook('printthread_start', 'mgcvthreads_block');

function mgcvthreads_info()
{
    return array(
        "name"        => "Member groups cant view threads",
        "description"    => "Shows a no permission page to selected user groups.<br />When they try to view a thread.",
        "website"        => "http://community.mybb.com/user-59864.html",
        "author"        => "Anori",
        "authorsite"    => "http://community.mybb.com/user-59864.html",
        "version"        => "1.4.2",
        "guid"            => "4a1551bc46ad53fe28aae148d6cc7793",
        "compatibility" => "16*"
    );
}
function mgcvthreads_install()
{
    global $db;
    
    $insert_array = array(
        'title'        => 'mgcvthreads_no_permission',
        'template'    => $db->escape_string('{$lang->error_nopermission_guest_1}
<ol>
<li>{$lang->error_nopermission_guest_2}</li>
<li>{$lang->error_nopermission_guest_3}</li>
<li>{$lang->error_nopermission_guest_4}</li>
<li>{$lang->error_nopermission_guest_5}</li>
</ol>
<form action="member.php" method="post">
<input type="hidden" name="action" value="do_login" />
<input type="hidden" name="url" value="{$redirect_url}" />
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="2"><span class="smalltext"><strong>{$lang->login}</strong></span></td>
</tr>
<tr>
<td class="trow1"><strong>{$lang->username}</strong></td>
<td class="trow1"><input type="text" class="textbox" name="username" tabindex="1" /></td>
</tr>
<tr>
<td class="trow2"><strong>{$lang->password}</strong></td>
<td class="trow2"><input type="password" class="textbox" name="password" tabindex="2" /></td>
</tr>
<tr>
<td class="trow2" colspan="2"><span class="smalltext" style="float:right; padding-top:3px;"><a href="member.php?action=register">{$lang->need_reg}</a> | <a href="member.php?action=lostpw">{$lang->forgot_password}</a>&nbsp;</span>&nbsp;<input type="submit" class="button" value="{$lang->login}" tabindex="3" /></td>
</tr>
</table>
</form>
<br />'),
        'sid'        => '-1',
        'version'    => '',
        'dateline'    => TIME_NOW
    );
    $db->insert_query("templates", $insert_array);
    
    $insert_array2 = array(
        'title'        => 'mgcvthreads_no_permission_loggedin',
        'template'    => $db->escape_string('{$lang->error_nopermission_user_1}
<ol>
    <li>{$lang->error_nopermission_user_2}</li>
    <li>{$lang->error_nopermission_user_3}</li>
    <li>{$lang->error_nopermission_user_4} (<a href="member.php?action=resendactivation">{$lang->error_nopermission_user_resendactivation}</a>)</li>
    <li>{$lang->error_nopermission_user_5}</li>
</ol>
<br />
{$lang->error_nopermission_user_username}'),
        'sid'        => '-1',
        'version'    => '',
        'dateline'    => TIME_NOW
    );
    $db->insert_query("templates", $insert_array2); 
    
    $gid = $db->insert_query('settinggroups', array(
        'name' => 'mgcvthreads',
        'title' => 'Member groups cant view threads',
        'description' => "Settings for the Member groups cant view threads plugin",
        'disporder' => 1,
        'isdefault' => 0
    ));
        $db->insert_query('settings', array(
        'name' => 'mgcvthreads_enable',
        'title' => 'Enable or Disable Plugin',
        'description' => 'Enable or disable the plugin',
        'optionscode' => 'onoff',
        'value' => '1',
        'disporder' => 1,
        'gid' => $gid
    ));
    $db->insert_query('settings', array(
        'name' => 'mgcvthreads_groups',
        'title' => 'Select the user groups',
        'description' => 'Select which user groups are not allowed to view threads (use , to sepperate multiple user groups).',
        'optionscode' => 'text',
        'value' => '1',
        'disporder' => 2,
        'gid' => $gid
    ));
    $db->insert_query('settings', array(
        'name' => 'mgcvthreads_template',
        'title' => 'Use custom no permissions template',
        'description' => 'Do you wish to use custom no permission templates, or do you wish to use the MyBB default no_permission templates?',
        'optionscode' => 'radio
cust=Custom no_permission templates.
def=Default MyBB no_permission templates.',
        'value' => 'cust',
        'disporder' => 3,
        'gid' => $gid
    ));
    $db->insert_query('settings', array(
        'name' => 'mgcvthreads_forums',
        'title' => 'For which forums this plugin should run.',
        'description' => 'Select in which forums you wish to run this plugin.<br /> 
Leave empty to enable it in all the forums, or to run it in multiple forums use commas to sepperate them: <br /> 
Example: 1,2,3,4',
        'optionscode' => 'text',
        'value' => '',
        'disporder' => 4,
        'gid' => $gid
    ));
    rebuild_settings();
}

function mgcvthreads_is_installed()
{
    global $mybb, $db;
    
    $query = $db->simple_select("settinggroups", "name", "name = 'mgcvthreads'");
    $result = $db->fetch_array($query);
    if($result)
        return true;
    else return false;
}

function mgcvthreads_activate()
{
}
function mgcvthreads_deactivate()
{    
}
function mgcvthreads_uninstall()
{
    global $db;
    require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
    
    $db->delete_query("templates", "title IN ('mgcvthreads_no_permission')");
    $db->delete_query("templates", "title IN ('mgcvthreads_no_permission_loggedin')");
    $db->delete_query("settinggroups", "name = ('mgcvthreads')");
    $db->delete_query("settings", "name IN ('mgcvthreads_enable')");
    $db->delete_query("settings", "name IN ('mgcvthreads_groups')");
    $db->delete_query("settings", "name IN ('mgcvthreads_template')");
    $db->delete_query("settings", "name IN ('mgcvthreads_forums')");
}
function mgcvthreads_block() 
{
    global $mybb, $lang, $thread, $templates, $fid;

    if($mybb->settings['mgcvthreads_enable'] == "1")  
    {
        $mgcvtFid = '';
        if($mybb->settings['mgcvthreads_forums'] !== '')
        {
            $mgcvtFid = $thread['fid'];
            if(!$mgcvtFid || $mgcvtFid === '')
            {
                $mgcvtFid = $fid;
                if(!$mgcvtFid || $mgcvtFid === '')
                {
                    error($lang->error_invalidthread);
                }
            }
        }
        $mgcvtForums = explode(',',$mybb->settings['mgcvthreads_forums']);
        if((in_array($mgcvtFid, $mgcvtForums)) or ($mybb->settings['mgcvthreads_forums'] === ''))
        {
            $mgcvtGroups = explode(",", $mybb->settings['mgcvthreads_groups']);
            if(in_array($mybb->user['usergroup'], $mgcvtGroups))
            {
                $lang->load("messages");
                $lang->load("global");
                if($mybb->user['uid'])
                {
                    if($mybb->settings['mgcvthreads_template'] == "cust")
                    {
                        $lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, $mybb->user['username']);
                        eval("\$mgcvthreads_no_permission_loggedin = \"".$templates->get("mgcvthreads_no_permission_loggedin")."\";");
                        error($mgcvthreads_no_permission_loggedin);
                    }
                    else
                    {
                        error_no_permission();
                    }

                }
                else
                {
                    if($mybb->settings['mgcvthreads_template'] == "cust")
                    {
                        eval("\$mgcvthreads_no_permission = \"".$templates->get("mgcvthreads_no_permission")."\";");
                        error($mgcvthreads_no_permission);
                    }
                    else
                    {
                        error_no_permission();
                    }
                
                }
            }
        }
    }
}
?>
Make sure that there is no blank space before or after PHP tags.
(2013-11-03, 07:29 PM)Yaldaram Wrote: [ -> ]Make sure that there is no blank space before or after PHP tags.

Said the same thing, but the only blank spaces before any real code is between the */ and the hooks.
Find it so weird Confused not able to reproduce it either locally so.
Try the attachment, it shouldn't give you error in Plugin's Manager;
[attachment=30453]
(2013-11-03, 08:06 PM)Yaldaram Wrote: [ -> ]Try the attachment, it shouldn't give you error in Plugin's Manager;

What is the difference between the two if i may ask.
I did spot two lines:

202 / 215 that i probably should remove the whitespace.
There is no difference at all really, I just copied the code provided above and paste into a file, it doesn't show me the error when I checked. So I think there may be blank spaces before and after PHP tags which were not pasted in the code above hence no error here.

And the lines 202 and 215 are not blank actually, though these doesn't have any code and considered as blank but the blank means any space before <?php or after ?>
(2013-11-03, 08:24 PM)Yaldaram Wrote: [ -> ]There is no difference at all really, I just copied the code provided above and paste into a file, it doesn't show me the error when I checked. So I think there may be blank spaces before and after PHP tags which were not pasted in the code above hence no error here.

And the lines 202 and 215 are not blank actually, though these doesn't have any code and considered as blank but the blank means any space before <?php or after ?>

Oh the last part i knew, just to make it look nicer i should remove those two lines. Might i guess be pastebin inserting the two lines in the end for the person in question then.

Then this should work:

1.4.2
[attachment=30454]
thanks.. Now i can use the plugin Big Grin
How to fix when certain thread needed to login via lite archieve page but the login or register link is not exits.

archive/index.php/member.php?action=register

so the user got this error message

The requested page was not found on this server.
If you have custom error templates enabled there is this line:

<td class="trow2" colspan="2"><span class="smalltext" style="float:right; padding-top:3px;"><a href="member.php?action=register">{$lang->need_reg}</a> | <a href="member.php?action=lostpw">{$lang->forgot_password}</a>&nbsp;</span>&nbsp;<input type="submit" class="button" value="{$lang->login}" tabindex="3" /></td>
</tr>

<a href="member.php?action=register">


What you could always change the url to the full URL. Same applies for the default error templates.
Pages: 1 2