$userid = isset($_SESSION["userid"]) ? $_SESSION["userid"] : null;
$lastcomment = isset($_SESSION["lastcomment"]) ? $_SESSION["lastcomment"] : null;
$response = array();
$response["result"] = false;
$curtime = time();
if ($lastcomment != null && $curtime - $lastcomment < 5) {
    $response["feedback"] = "!-- don't comment too frequently";
} else {
    if ($activityid > 0 && $userid != null) {
        include_once "../model/connect.php";
        include_once "../model/activitymodel.php";
        include_once "../model/audiencemodel.php";
        include_once "../model/commentmodel.php";
        include_once "../model/filter.php";
        $conn = getConnection();
        if (getActivityState($conn, $activityid) == 1) {
            if (getmsgAuthority($conn, $activityid, $userid) == 0) {
                $content = commentFilter($content);
                $response["result"] = addComment($conn, $activityid, $userid, $content);
                $_SESSION["lastcomment"] = $curtime;
            } else {
                $response["feedback"] = "you are not allowed to comment by the administrator";
            }
        } else {
            $response["feedback"] = "this activity not exists or has been closed";
        }
        mysql_close($conn);
    } else {
        $response["feedback"] = "!-- you are not online";
    }
}
<?php

// deal request for trying to join an activity (ok)
session_start();
$activityid = intval($_POST["activityid"]);
$audienceid = isset($_SESSION["userid"]) ? $_SESSION["userid"] : null;
$response = array();
$response["result"] = false;
if ($activityid > 0 && $audienceid != null) {
    include_once "../model/connect.php";
    include_once "../model/activitymodel.php";
    include_once "../model/audiencemodel.php";
    $conn = getConnection();
    if (getActivityState($conn, $activityid) == 1 && contains($conn, $activityid, $audienceid) == false) {
        $response["result"] = joinActivity($conn, $activityid, $audienceid);
    }
    mysql_close($conn);
}
header("Content-Type:application/json;charset=utf-8");
echo json_encode($response);