Slowie Posted June 6, 2011 Share Posted June 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238562-dynamic-headers/ Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 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); } Quote Link to comment https://forums.phpfreaks.com/topic/238562-dynamic-headers/#findComment-1225936 Share on other sites More sharing options...
Slowie Posted June 6, 2011 Author Share Posted June 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238562-dynamic-headers/#findComment-1225944 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 only if your pathing changes, not sure why your document root wouldn't work Quote Link to comment https://forums.phpfreaks.com/topic/238562-dynamic-headers/#findComment-1225951 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.