mattyt81 Posted April 5, 2012 Share Posted April 5, 2012 HI I have a script which runs to check if a user is logged in or not, it also outputs links to member home etc. I would like those links to change depending on what account type the member has registered under. I didn't think this would be that hard but I have tried many variations and nothing seems to work. I have pasted my current method and all code below. If anyone has any ideas I would appreciate it. <?php session_start(); // error_reporting(E_ALL); // ini_set('display_errors', '1'); // Turn on all error reporting error_reporting(0); // Turn off all error reporting //----------------------------------------------------------------------------------------------------------------------------------- include_once "PHPScripts/connect_to_mysql.php"; // Connect to the database $dyn_www = $_SERVER['HTTP_HOST']; //------ CHECK IF THE USER IS LOGGED IN OR NOT AND GIVE APPROPRIATE OUTPUT ------- $logOptions = ''; // Initialize the logOptions variable that gets printed to the page // If the session variable and cookie variable are not set this code runs if (!isset($_SESSION['idx'])) { if (!isset($_COOKIE['idCookie'])) { $logOptions = ' <ul> <br/><br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/register.php">Register Account</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/login.php">Log In</a> </ul> '; } } // If session ID is set for logged in user without cookies remember me feature set if (isset($_SESSION['idx'])) { $decryptedID = base64_decode($_SESSION['idx']); $id_array = explode("p3h9xfn8sq03hs2234", $decryptedID); $logOptions_id = $id_array[1]; // Ready the output for this logged in user mysql_query("SELECT * FROM memberdata "); if ($accounttype == "GYM") { $logOptions = ' <ul> <a style="text-decoration:none;" href="http://'.$dyn_www.'/gymmemberhome.php">Member Home</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/gymmemberaccount.php?id='.$logOptions_id.'">Edit Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/gymmemberprofile.php?id='.$logOptions_id.'">View Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/logout.php">Log Out</a> </ul> '; }else if ($accounttype == "PT") { $logOptions = ' <ul> <a style="text-decoration:none;" href="http://'.$dyn_www.'/ptmemberhome.php">Member Home</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/ptmemberaccount.php?id='.$logOptions_id.'">Edit Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/ptmemberprofile.php?id='.$logOptions_id.'">View Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/logout.php">Log Out</a> </ul> '; } } else if (isset($_COOKIE['idCookie'])) {// If id cookie is set, but no session ID is set yet, we set it below and update stuff $decryptedID = base64_decode($_COOKIE['idCookie']); $id_array = explode("nm2c0c4y3dn3727553", $decryptedID); $userID = $id_array[1]; $userPass = $_COOKIE['passCookie']; // Get their user first name to set into session var $sql_uname = mysql_query("SELECT email FROM memberdata WHERE id='$userID' AND password='$userPass' LIMIT 1"); $numRows = mysql_num_rows($sql_uname); if ($numRows == 0) { // Kill their cookies and send them back to homepage if they have cookie set but are not a member any longer setcookie("idCookie", '', time()-42000, '/'); setcookie("passCookie", '', time()-42000, '/'); header("location: index.php"); // << makes the script send them to any page we set exit(); } while($row = mysql_fetch_array($sql_uname)){ $useremail = $row["email"]; } $_SESSION['id'] = $userID; // now add the value we need to the session variable $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$userID"); $_SESSION['useremail'] = $useremail; $_SESSION['userpass'] = $userPass; $logOptions_id = $userID; /////////// Update Last Login Date Field ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// mysql_query("UPDATE memberdata SET last_log_date=now() WHERE id='$logOptions_id'"); // Ready the output for this logged in user if ($accounttype == "GYM") { $logOptions = ' <ul> <a style="text-decoration:none;" href="http://'.$dyn_www.'/gymmemberhome.php">Member Home</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/gymmemberaccount.php?id='.$logOptions_id.'">Edit Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/gymmemberprofile.php?id='.$logOptions_id.'">View Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/logout.php">Log Out</a> </ul> '; }else if ($accounttype == "PT") { $logOptions = ' <ul> <a style="text-decoration:none;" href="http://'.$dyn_www.'/ptmemberhome.php">Member Home</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/ptmemberaccount.php?id='.$logOptions_id.'">Edit Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/ptmemberprofile.php?id='.$logOptions_id.'">View Profile</a> <br/> <a style="text-decoration:none;" href="http://'.$dyn_www.'/logout.php">Log Out</a> </ul> '; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260381-php-output-for-logged-in-user/ 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.