How to pass variables or parameters from one Joomla article to another using DirectPHP?

One of the most commonly asked questions for DirectPHP is: how do you pass a variable or parameter from one Joomla page to another?

In a plain PHP page, you can easily do this with:


But try this in a Joomla article using DirectPHP. Most likely you will be directed somewhere else and your article will not appear.


Let's see a quick demo of this in action first.

var1 and var2 below are currently empty:

var1 = value1
var2 = value2

The codes that produce the above are:

echo "var1 = ".$_GET['var1']."<br />";
echo "var2 = ".$_GET['var2']."<br />";

Now click on this link which contains:

Did you see that the two parameters above have been populated with 'value1' and 'value2' respectively?


If you take a look at the URL of your Joomla articles, you should see that each article is identified by 4 key parameters:

  • option: This is the component used to display the article, which is com_content
  • Itemid: This is the menu id associated with this article. It determines which modules will be displayed together with this article.
  • id: This is the unique id of the article.
  • view: This tells the component that you want the article view.

For this article that you are viewing right now, you can see that the 4 values are:

  • option: com_content
  • Itemid: 1
  • id: 2013
  • view: view

If you are using languages other than English, you might also need to pass in the parameter lang.


To pass variables or parameters from one Joomla article to another, in addition to the parameters you want to pass, you must also remember to pass in the following variables:

  1. option
  2. Itemid
  3. id
  4. view
  5. lang (if you are using languages other than English)

For example:


0 # Krutika 2012-12-06 05:19
Thanks a lot! Was boggling my head for hours over this..
Reply | Reply with quote | Quote
0 # potro 2013-03-30 19:35
i am using directPHP IN joomla2.5, i SET no filtering. Its jumping form FORM page to action page,but nothing is showing when I echo $_POST['var1'], and i want to interact with database also, can you pleas help me?
Reply | Reply with quote | Quote
0 # Stormy 2013-11-10 18:00
I am using joomla 3.2 with directphp, I have set filtering to no but when I launch the command below but the page is not found 404 error though the values display in the URL line
Reply | Reply with quote | Quote
-1 # kksou 2013-11-10 18:52

You said "when I launch the command below".

What is that "command" that you are referring to?

Also, for "the page is not found 404 error", what is the complete url that you see at the top of the browser?

Reply | Reply with quote | Quote
-1 # Stormy 2013-11-10 20:07
This is the $tout[$n}
Is the command in the field in a table with URL
Reply | Reply with quote | Quote
-1 # Stormy 2013-11-10 20:09
This is what I launch, sorry it did not show in the last note.
Reply | Reply with quote | Quote
0 # hsnin 2013-12-08 04:53
I am using:

$itemid =JRequest::getVar('Itemid');
$id = JRequest::getVar('id');

to get the itemid en id, thats working but how do I pass the variables with directPHP in the INPUT statement?

Reply | Reply with quote | Quote
+1 # Paul Seyler 2016-01-20 19:41
Is it possible to use this technique to pass values from a page to a module ON the page? I have a Salesforce WebToLead form that needs to have different values for campaign ID, Lead Source, etc. every time it's used on a different landing page. Could I use this tool/approach to pass those values to the module containing the form? If not, is there another approach that would work? Thanks!
Reply | Reply with quote | Quote
0 # kksou 2016-01-22 02:34
Hi Paul,

You can pass any parameters. The key thing is whether your module can receive that.

So you need to look at your module how it retrieves those parameters. E.g. if it uses $_GET, then you can use DirectPHP to pass the variables as method=GET. However, if it uses $_POST, then you have to use method=POST.

Warm Regards,
Reply | Reply with quote | Quote
0 # Marc 2016-01-24 20:12
I'am using joomla vers 3.4.8. I added the plugin, and php part is working.
but i tried to pass variables as above but it doesn't work.
I typed the url in the browser. the page with article shows up, but not my variable.
did I miss any setting in Joomla?
Reply | Reply with quote | Quote

Add comment

Security code