TeddyKiller Posted April 4, 2010 Share Posted April 4, 2010 I've got the best of it done with a function. The function requires "$user" and if the user isn't logged in, in some places it'll display a logged out user navigator. So without most the features. Now.. I'm not able to do something similar to.. if($user){ //display logged in navigator } else { //display logged out navigator } in a function. So far I have this (code below), I haven't tested it but it should only get the logged in users navigator. It's similar to above code really.. except my best shot in a function. check_user function will redirect users if they aren't logged in. So for pages in which they have no need to redirect I have a little.. check if they are logged in, and if so to go to the check_user funciton for further checking, else the check user function isn't called. There for $user isn't defined. For example.. if(isset($_SESSION['uid']) && isset($_SESSION['hash'])){ $user = check_user($secret_key); } else { session_unset(); } Though in this case it may be possible to do $user = ''; for when the user isn't isn't logged in. Although that wouldn't quite work as the way the function is setup, it will still display a logged in users navigator as it only does if($user){ blah } The function is below, can you help? Thanks! function header_display($user) { $header = '<div id="extra">'; if($user){ $header .= '<span><a style="margin-bottom:8px;" href="#">My Account</a> | <a href="logout.php">Log Out</a></span>'; } else { echo '<span><a style="margin-bottom:8px;" href="?action=register">Sign Up</a> | <a href="/">Log In</a></span>'; } $header .= '</div> <div id="navigator"><ul id="topnav">'; if($user){ $header .= '<li><a href="/main.php">Home</a></li> <li><a href="/main.php?sk=wall">Horble Wall</a></li> <li><a href="/mail.php">Mail('; $query = mysql_query("select * from `sent_messages` where `status`='unread' and `to_id`='$user->id'"); $number = mysql_num_rows($query); $header .= $number; $header .= ')</a></li>'; } else { echo '<li><a href="/">Home</a></li>'; } $header .= '</ul></div>'; return $header; } Quote Link to comment https://forums.phpfreaks.com/topic/197573-how-can-i-functionise-this/ Share on other sites More sharing options...
DavidAM Posted April 4, 2010 Share Posted April 4, 2010 if (! empty($user)) { // We have a value in the user variable } else { // The user variable does not contain a value // You end up here if $user is an empty string (''), // or zero (0), or false, or not set, etc. } Quote Link to comment https://forums.phpfreaks.com/topic/197573-how-can-i-functionise-this/#findComment-1036912 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.