Jump to content

Dynamic Headers


Slowie

Recommended Posts

Hi Guys Another problem here i currently have two header files on my website

 

what i want is when a user logs in they get the header which applies to their account.

 

currently i have this code in a php file

 

function company() {

  list($branch) = mysql_fetch_row(mysql_query("select branch from StaffList where id='$_SESSION[user_id]'"));

	  $_SESSION['branch'] = $branch;

If 		  ($_SESSION['branch'] == 1)  $Jakata = $_SERVER['DOCUMENT_ROOT'];
								 $Jakata .= "/Header/headerj.php";
													include($Jakata);

If 		  ($_SESSION['branch'] == 2) $Paul = $_SERVER['DOCUMENT_ROOT'];
								$Paul .= "/Header/headert.php";
													include ($Paul);
}

 

then in each php file i have at the top the include method to include this script then under that

 

Company() to call the correct header

however i recieve this error upon loggining in

 

Notice: Undefined variable: Jakata in /var/www/dbc.php on line 284 Warning: include(/Header/headerj.php): failed to open stream: No such file or directory in /var/www/dbc.php on line 285 Warning: include(): Failed opening '/Header/headerj.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/dbc.php on line 285

 

what have i dont wrong guys?

Link to comment
https://forums.phpfreaks.com/topic/238562-dynamic-headers/
Share on other sites

well its indicating that the file you are trying to include does not exist. try cleaning up your code a little.

if ($_SESSION['branch'] == 1)  {

   $Jakata = $_SERVER['DOCUMENT_ROOT'];
   $Jakata .= "/Header/headerj.php";
   include($Jakata);													
}

if ($_SESSION['branch'] == 2) {

   $Paul = $_SERVER['DOCUMENT_ROOT'];
   $Paul .= "/Header/headert.php";
   include ($Paul);
}

Link to comment
https://forums.phpfreaks.com/topic/238562-dynamic-headers/#findComment-1225936
Share on other sites

Yeah I was over complicating thing

 

in the end this works

 

 

function company() {

  list($branch) = mysql_fetch_row(mysql_query("select branch from StaffList where id='$_SESSION[user_id]'"));
  $Jakata = "/var/www/Header/headerj.php"; 
  $Paul = "/var/www/Header/headert.php"; 

	  $_SESSION['branch'] = $branch;

If 		  ($_SESSION['branch'] == 1) include($Jakata); 


If 		  ($_SESSION['branch'] == 2) include($Paul); 
}

 

is it bad coding to include the entire directory though?

Link to comment
https://forums.phpfreaks.com/topic/238562-dynamic-headers/#findComment-1225944
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.