NEVER rely on $_SERVER['HTTP_REFERER'] as it is not always sent...
When "echoing" iframes, you could add a variable to the query string... example...
current page is 'index'...
let's output an iframe with an SRC pointing to a common file (let's say show_iframe_contents.php) ending with &page=current_page, so : show_iframe_contents.php?...&page=index
In the show_iframe_contents.php, get the page value ($GET['page'] or $REQUEST['page']) and then associate it to what it should be associated with...