Administrator
- Join Date:
- Sep 2009
- Location:
- Stuart, FL
- Posts:
- 14,100
- Plugin Contributions:
- 56
Why isn't my global variable working?
I've got two functions that I'll use to set/get the url of the previous page, and the variable $backlinks[$page] needs to be persistent. The idea is that you'd call lat9_set_backlink('PAGE') at the start of processing for the page and then call lat9_get_backlink('PAGE') at the end of the page to provide the href for a "Back" button.
What's happening is as soon as the user navigates off the PAGE, the $backlinks variable reverts to "".
Please help, this is driving me (more) nuts!
Here's the code:
/*----
** Creates a global variable named $page_backlink that holds the backlink to the page that
** called the calling page.
*/
function lat9_set_backlink($page) {
global $backlinks;
if (strpos( zen_back_link(), 'main_page=' . $page) === false ) {
echo '<br />Setting backlink for ' . $page . ' to ' . zen_back_link();
$backlinks[$page] = zen_back_link();
}
}
/*----
** Returns the variable previously recorded by lat9_set_backlink
*/
function lat9_get_backlink($page) {
global $backlinks;
if (isset($backlinks[$page])) {
$link = $backlinks[$page];
} else {
$link = '** No previous set for ' . $page .'_backlink';
}
return $link;
}