Joomla! Custom form logs the user out on submissio

2019-08-06 08:56发布

问题:

I have the following php embedded into a Joomla! article, using the Sorcerer plugin;

<?php

$user = JFactory::getUser();
$username = $user->username;
$user_id = $user->id;
if (isset($_GET['action'])){

    date_default_timezone_set('Europe/London');    
    $user= JFactory::getUser();
    $username=$user->username;
    $user_id=$user->id;
    $date_now=date('m/d/Y H:i:s');

    $db =& JFactory::getDBO();
    $insert_sql= "INSERT INTO KOSRequest (user_id,created,IGN,LKL,KOSReason,Status) VALUES (".$user_id.",'".$date_now."','".$_POST['$IGN']."',". $_POST['LKL'].",'".$_POST$['KOSReason']."','Pending')";  
    $db->setQuery($insert_sql);    
    $db->execute(); 
    echo "A new KOS entry has been added by ".$username."<br />"; 

} else {   
    echo"
        <form name='kos_entry' action='http://www.ospalliance.org.uk/JOOM/2-uncategorised/51-kill-on-sight-form?action=submit' method='POST'>
            Player IGN <input type='text' name='IGN' required /><br />
            Player Location :<input type='number' name='LKL' required /><br />
            Reason: <textarea rows='4' cols='50' name='KOSReason'></textarea><br />
            <input type='submit' value='Sumbit'>";
}

?>

My issue is that whenever the submit button is pressed, Joomla! logs the user out with the system message:

You have been redirected to the home page following logout

I can directly access the hyper-link specified in the action clause.

NB The SQL itself does the insert correctly (only if I replace the $_POST variables directly (because $_POST never reaches that point, I have to replace the variables like this);

$IGN='SomeIGN';
$LKL=1200;
$KOSReason='some reason';

But the primary question is , why does the user get logged out from Joomla!?

I have many many other forms which use this same logic, which work fine.

One difference might be that the server was upgraded by the host recently.

Working Scripts were created prior to the upgrade , but I wouldn't know where/how the setup is different.

Please help!

标签: php joomla