API15

JRequest/checkToken

From Joomla! Documentation

< API15:JRequest
Revision as of 17:19, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Checks for a form token in the request <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Checks for a form token in the request

[Edit Descripton]

Template:Description:JRequest/checkToken

Syntax[edit]

checkToken($method= 'post')
Parameter Name Default Value Description
$method 'post' The request method in which to look for the token key

Returns[edit]

boolean True if found and valid, false otherwise

Defined in[edit]

libraries/joomla/environment/request.php

Importing[edit]

jimport( 'joomla.environment.request' );

Source Body[edit]

function checkToken( $method = 'post' )
{
        $token  = JUtility::getToken();
        if(!JRequest::getVar( $token, '', $method, 'alnum' )) {
                $session = JFactory::getSession();
                if($session->isNew()) {
                        //Redirect to login screen
                        global $mainframe;
                        $return = JRoute::_('index.php');
;                               $mainframe->redirect($return, JText::_('SESSION_EXPIRED'));
                        $mainframe->close();
                } else {
                        return false;
                }
        } else {
                return true;
        }
}

[Edit See Also] Template:SeeAlso:JRequest/checkToken

Examples[edit]

<CodeExamplesForm />