andrew_biggart Posted May 11, 2009 Share Posted May 11, 2009 Ok ive been trying to get this to work for days! But is it possible to have this code on a seperate page and use an include on every page you want it in? <?php $username=$_SESSION['myusername']; if(isset($_SESSION['myusername'])) { echo " <img alt='' src='../icons/myacc.gif' width='12' height='11' /> <a class='button6' href='my_profile.php'>My Account</a> <img alt='' src='../icons/mypro.gif' width='12' height='11' /> <a class='button6' href='profile.php?username=$username'>My Profile</a> <img alt='' src='../icons/mymes.gif' width='12' height='11' /> <a class='button6' href='my_profile_messages.php'>My Messages</a> <img alt='' src='../icons/myale.gif' width='11' height='11' /> <a class='button6' href='my_profile_alerts.php'>My Alerts</a> <img alt='' src='../icons/myreq.gif' width='12' height='11' /> <a class='button6' href='my_profile_requests.php'>My Requests</a> <img alt='' src='../icons/myfri.gif' width='12' height='11' /> <a class='button6' href='my_profile_friends.php'>My Friends</a> <img alt='' src='../icons/mylog.gif' width='12' height='12' /> <a class='button6' href='logout.php'>Logout</a> "; } else{ echo " <form method='post' action='check_login.php'> <table style='float: right'> <tr> <td><img alt='' src='../Header_images/login.jpg' width='120' height='18' /></td> <td><input class='username' name='myusername' type='text' value='Username'/></td> <td class='logmein'>:Username</td> <td><input class='password' name='mypassword' type='password' value='Password'/></td> <td class='logmein'>:Password</td> <td><input class='submit' name='Submit2' type='submit' value='Cumon in'/><a href='user_register.htm'><input class='register' name='Submit2' type='button' value='Register'/></a></td> </tr> </table> </form> "; } ?> So thats the code i want to have on the include page! called navmenu.php and ive been trying this code to try and include it on my test page but its not working. <?php include("navmenu.php"); ?> I am doing something wrong? Thanks in advance Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 11, 2009 Share Posted May 11, 2009 Make sure you are calling session_start before you include navmenu.php. Remember before you use $_SESSION variables you need to start the session first. Example <?php session_start(); // some other code here include("navmenu.php"); ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted May 11, 2009 Share Posted May 11, 2009 You need to have session_start at the top of your include script. I would use require instead: You can read the differences here: Require. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 11, 2009 Author Share Posted May 11, 2009 ok i have got it working now thanks! i already had the session start at the top the problem was infact the path to the include file! Thanks guys Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 11, 2009 Author Share Posted May 11, 2009 Im still having some trouble with this! it is injecting the correct php but its not appearing inside the div proberly where it should be its slightly below it! any ideas? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 11, 2009 Share Posted May 11, 2009 This will be a HTML/CSS issue. Nothing to do with PHP. Quote Link to comment Share on other sites More sharing options...
Maq Posted May 11, 2009 Share Posted May 11, 2009 We also need to see the code and related CSS. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 11, 2009 Author Share Posted May 11, 2009 ok il give you the code and see what u can spot! Required file! <?php $username=$_SESSION['myusername']; if(isset($_SESSION['myusername'])) { echo " <img alt='' src='../icons/myacc.gif' width='12' height='11' /> <a class='button6' href='my_profile.php'>My Account</a> <img alt='' src='../icons/mypro.gif' width='12' height='11' /> <a class='button6' href='profile.php?username=$username'>My Profile</a> <img alt='' src='../icons/mymes.gif' width='12' height='11' /> <a class='button6' href='my_profile_messages.php'>My Messages</a> <img alt='' src='../icons/myale.gif' width='11' height='11' /> <a class='button6' href='my_profile_alerts.php'>My Alerts</a> <img alt='' src='../icons/myreq.gif' width='12' height='11' /> <a class='button6' href='my_profile_requests.php'>My Requests</a> <img alt='' src='../icons/myfri.gif' width='12' height='11' /> <a class='button6' href='my_profile_friends.php'>My Friends</a> <img alt='' src='../icons/mylog.gif' width='12' height='12' /> <a class='button6' href='logout.php'>Logout</a> "; } else{ echo " <form method='post' action='check_login.php'> <table style='float: right'> <tr> <td><img alt='' src='../Header_images/login.jpg' width='120' height='18' /></td> <td><input class='username' name='myusername' type='text' value='Username'/></td> <td class='logmein'>:Username</td> <td><input class='password' name='mypassword' type='password' value='Password'/></td> <td class='logmein'>:Password</td> <td><input class='submit' name='Submit2' type='submit' value='Cumon in'/><a href='user_register.htm'><input class='register' name='Submit2' type='button' value='Register'/></a></td> </tr> </table> </form> "; } ?> and this is being injected hear! <div id="nav_menu"> <?php require_once("../Includes/navmenu.php"); ?> </div> and the css im using for the div is #nav_menu { width:640px; height:25px; background-image:url('../Layout_images/menu_new.gif'); background-repeat:no-repeat; padding-left:188px; padding-right:60px; padding-top:5px; text-align:right; } I have been able to include my flash banner and footer successfully i jut cant get this php to work properly! it adds it to the page but 30-40px below where it should be! im not able to use the login form! and it moves the flash banner down with it! How ever when i remove the nav code and keep the flash banner require there the banner is in the correct place! Thanks Quote Link to comment Share on other sites More sharing options...
Maq Posted May 11, 2009 Share Posted May 11, 2009 Assuming this is an issue with your CSS, I'm moving it there. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 11, 2009 Share Posted May 11, 2009 Any reason you're floating your table to the right? Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 11, 2009 Author Share Posted May 11, 2009 Im not really sure to be honest but i removed it and then the login form disappear!! im assuming it was behind the flash banner! Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 11, 2009 Author Share Posted May 11, 2009 Its weird because it works perfectly when i directly put the php code directly into the div! but when i try to add it via a php include page it doesnt! Quote Link to comment 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.