This topic is locked

$_SESSION variables in header.php (3.1 143)

9/6/2006 9:22:11 AM
PHPRunner General questions
F
francesco author

Hi
I need to insert some code in header.php.

My header is an HTML tab menu that links some detail tables, and i need to pass the master key toghether with the page name (the link could look like this http://localhost/mysite/tb_detail_list.php?mastertable=tb_master&masterkey1=3 where
tb_master = master table

tb_detail= detail table)
The problem is that all $_SESSION variables does not work in header.php

(I've tried with $_SESSION[$strTableName."_masterkey"])
Thx in advance for any suggestion

J
Jane 9/7/2006

Francesco,
use following code to pass master key on the header.php page:

global $strTableName;

echo $strTableName;

echo $_SESSION[$strTableName."_masterkey1"];

F
francesco author 9/8/2006

Francesco,

use following code to pass master key on the header.php page:


Hi Jane
Thx for replay, but all SESSION variabiles does not work in header php. You can use $strTableName as a global variable, but SESSION variabiles are inizialized later(in main page i.e. page_name_list.php.)

How can I do?

J
Jane 9/8/2006

Francesco,
header and footer files are called after definition of all session variables.

So you can use $_SESSION variables in the header.php file.

Please note that $_SESSION[$strTableName."_masterkey1"] variable is defined only when you proceed to the detail table from master table.

F
francesco author 9/8/2006

Francesco,

header and footer files are called after definition of all session variables.

So you can use $_SESSION variables in the header.php file.

Please note that $_SESSION[$strTableName."_masterkey1"] variable is defined only when you proceed to the detail table from master table.


Hi Jane
Thx for replaying again.
You hit the spot. You have right, header and footer files are called after definition of all session variables.

Looking up the code, I've seen that everything is defined because html page (toghether with header and footer) is shown with

smarty-->display("table_name_list.htm")



at the and of evry php file. (I love this product!!!).
The problem is that I need the value of that variable just in order to display detail table.

I do not have menu page, and my first page is a list containing user main data.

On top of each page, I have an html menu (in header file) with all the links to the detail tables, security acces is set for allowing the user to see only his data.
The question is that list page kows for sure the primary key value i need, (i.e. the foreign key value in detail table) but i cannot access it directly.
My solution:
in header.php

<?php

global $row;
// give me masterkey value for detail table i need to display (well, return the whole where clause)

$detail_table_where_clause= $row["1detail_table_masterkeys"];
//so i can build href link in menu item in this way

<a href="detail_table_list.php?<?php echo $detail_table_where_clause ?>...
?>


Can you tell me if is it correct or if there is a better way to do this?
Thx anyway

J
Jane 9/11/2006

Francesco,
I'm not sure that I understand you correctly.

Please clarify where and how did you define $row["1detail_table_masterkeys"] variable.

Also give me an example of link you want to receive.