Access variables populated in one page function for a different page function? Always null I have a module that creates a simple page. However in the page I want to link to iframes that I will generate in the module code.

Currently I have two hook_menu items: one for the simple page (no arguments), one for the iframe pages (with arguments).

However when I show the iframe, I need to get some values from a global variable that is populated from the simple page function but when I reference it in my function for the pages with arguments the variables are always null. I assume this is because drupal re-loads the .module page but skips running the simple page function when it loads the page with arguments, thus it doesn't populate the variables when it loads the iframe.

How could I populate my iframe with the variables from my simple page? Is there an easier way than what I'm doing? Can I do it without global?

Does that make sense?

function my_custom_page() {} for:
    drupal/my-custom-page-module

function my_iframe($id) {} for:
    drupal/my-custom-page-iframe/0

Code for drupal/my-custom-page-iframe/0 needs to get variables that were generated in function my_custom_page() {} when it runs the my_iframe($id) for the page callback.

I have defined the variables outside functions as global and included global var_name in both functions but it still doesn't work.

Also, the iframe should not have any Drupal theme/sidebar content: for this I'm just echo'ing my code and then return: within my_iframe{$id}.

What I was thinking was instead of using two functions with page callback, was to just use GET request for my 'iframes' like ?iframe={$id}. Does that sound like a better direction to go?
First off, Drupal is bootstrapped every time a new page is requested. Even if both the pages  would be using the same menu callback, the global variables would be reset when passing from a page to the other one.

What you can do is using session variables, passing variables through the URL, or using a cache.
Passing variables through the URL would not use for complex variables, as there is a limit to the URL length accepted from browsers; using a cache would be a solution if the cached data should be available to more than one user, such as to user having the same rule; using session variables is the easier solution when the data to share are only for the currently logged-in users.

As for using the same callback, there is an example given in the hook_menu() documentation.

  function mymodule_menu() {
    $items['abc/def'] = array(
      'page callback' =&gt; 'mymodule_abc_view',
    );
    return $items;
  }

  function mymodule_abc_view($ghi = 0, $jkl = '') {
    // ...
  }


The menu callback would be used for http://example.com/abc/def, http://example.com/abc/def/222, and http://example.com/abc/def/333/aaaa. In the first case, $ghi and $jkl would get their default value; in the second case, only $ikl would get its default value; in the last case, none of the variables would get their default values.

That is true also for the form builder, with the exception that the first two arguments would be $form, and &amp;$form_state.