1 (edited by NettiCat 2009-10-26 16:41)

Topic: [extension release] Session For All Visitors (bug workaround)

Fix for always wrong captcha if missing cookie bug

Important: Installation of this extension makes sense only if you have pun_antispam installed
see also:
http://punbb.informer.com/forums/topic/ … -disabled/

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<!--
/**
 * Session For All Visitors (always set PHP session cookie and check on post))
 *
 * @package session_for_all_visitors
 */
-->

    <extension engine="1.0">
    <id>session_for_all_visitors</id>
    <title>Session For All Visitors (fix for always wrong captcha if missing cookie)</title>
    <version>1.0</version>
    <description>
        1. Tries to set a session cookie for all forum visitors (even guests).
        2. Checks for cookie if visitor is about to post and warns/aborts if cookie is missing.
    </description>
    <author>NettiCat</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.3.4</maxtestedon>
    <dependencies>
        <dependency>pun_antispam</dependency>
    </dependencies>



    <install>
        <![CDATA[
        ]]>
    </install>
    
    <uninstall>
        <![CDATA[
        ]]>
    </uninstall>

    <hooks>
        <hook id="in_start, vf_start, vt_start"><![CDATA[
            session_start();    //try to set cookie for all visitors, even for guests
        ]]>
        </hook>
        <hook id="rg_start, aop_start, li_start, po_start" priority="10"><![CDATA[
            if (!isset($_COOKIE["PHPSESSID"])) //warn when user is about to post
                message($lang_pun_antispam['Missing Cookie'] ? $lang_pun_antispam['Missing Cookie'] : 'Missing cookie. Please enable cookies and reload the page twice.');
        ]]>
        </hook>
    </hooks>

</extension>

Re: [extension release] Session For All Visitors (bug workaround)

You can add a dependency of your extension on pun_antispam to manifiest.xml with this code after maxtestedon tag:

    <dependencies>
        <dependency>pun_antispam</dependency>
    </dependencies>

Re: [extension release] Session For All Visitors (bug workaround)

Thank you - done.  smile

Re: [extension release] Session For All Visitors (bug workaround)

The warning message about enabling cookies makes sense only for guest posting. For other actions a user must be able to login and that's why he should have cookies enabled.

And I've added the message in this changeset: http://punbb.informer.com/trac/changeset/1401

So what does your extension do? Or I didn't get something and it does somesthing else?

5 (edited by NettiCat 2009-10-27 19:18)

Re: [extension release] Session For All Visitors (bug workaround)

Well, it makes sense for guest posting only, and since I have only guests (registering disabled) this was a major problem for me. In a privacy related forum most visitors in fact have cookies disabled.

Sorry, I could not know that you already fixed the problem, did not even know about those changesets.

However, besides the warning message this extension adds some session_start instructions for guests. Otherwise the forum would not set a cookie for guests, even if the guest has cookies enabled. (would only work if PHP automatically sets a session cookie for every website user, but I do not force cookies for everyone if not needed)