Question

Guyz, I have seen both of these in practical use quiet a lot...

JSession::getFormToken() vs JUtility::getToken()

Now I wish to know if they are the same(then why named differently), do they belong to different Joomla! versions, and if one is prefered which should I go with?

Note: I have searched enough and I must say both seem to be used equally, in official docs, tutorials, stackoverflow answers, etc..

UPDATE:- As of 7-FEB-2014 the official pages for both JSession::getFormToken() and JUtility::getToken() are showing this warning..

Joomla Deprecated Notice

While this page which is clearly intended for 2.5-3.xx states the use of

JSession::getFormToken()
Was it helpful?

Solution 2

I can say only one difference with these two.

It is based on Joomla api version. JUtility::getToken() is available from Joomla 1.5 and JSession::getFormToken available from Joomla 1.6.

In fact both are doing same task like here and this. So may be in future JUtility::getToken() may be depreciated or removed from latest versions like what Joomla did for DS constant Its available from J1.5 to J2.5 but on J3.x Its removed and they use DIRECTORY_SEPARATOR.

OTHER TIPS

According to me, the documentation pages of Joomla are updated. That's why you get those messages 'The Namespace has been archived'. Use http://api.joomla.org to find the new documentation.

JUtility::getToken() is deprecated. See: http://api.joomla.org/cms-2.5/classes/JUtility.html#method_getToken. It tells you to use JSession::getFormToken().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top