Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.