msacomputers Posted April 9, 2015 Share Posted April 9, 2015 I am working on a registration/login site. If the user's login is successful from my login.php page, I have a redirect to a loginsuccess.php page. From this page I need help setting up four different redirects based on user levels (0, 1, 2, 3). I’ve started with the following code, but no matter what the level of the user, my page redirects to hurray.php. How can I get this script to look at the user level in the database (my field is named user_level in my table) and how can I add multiple redirects to this page? $_SESSION['user_level'] = (int) $_SESSION['user_level']; // Changes the 1 or 2 user level to an integer. $url = ($_SESSION['user_level'] === 0) ? ‘hurray.php’: ‘index.php'; // Ternary operation to set the URL header('Location: ' . $url); // Makes the actual page jump. Keep in mind that $url is a relative path. exit(); // Cancels the rest of the script. My second question is why are two .php files listed in $url = ($_SESSION['user_level'] === 0) ? ‘hurray.php’: ‘index.php'; // ? Is the first what it goes to if successful, the second if it is not? Thanks so much for your assistance! Been stumped on this for awhile. Link to comment Share on other sites More sharing options...
Larry Posted April 15, 2015 Share Posted April 15, 2015 Yes, the ternary operator there says if $_SESSION['user_level'] is equal to 0, then $url is assigned 'hurray.php'. Otherwise, $url is assigned 'index.php'. To debug this, I'd start by verifying the value of $_SESSION['user_level']. Link to comment Share on other sites More sharing options...
Recommended Posts