How can I code $_SESSION to have three possible conditions?
These are the three possible types of conditions, the session can be student, corporate and institute:
if($_SESSION['user_id'] && $_SESSION['user_type']=="student"){
else if($_SESSION['user_id'] && $_SESSION['user_type']=="corporate"){
else if($_SESSION['user_id'] && $_SESSION['user_type']=="institute"){
If any of those sessions are there I want to show a profile buttons else a register button.
<?php if(isset($_SESSION())){?>
<a href="my-profile.php"><input type="button" value="VISIT YOUR PROFILE"></a>
<?php }else{ ?>
<a href="signup.php"><input type="button" value="REGISTER NOW"></a>
<?php } ?>
I think this is what you are trying to accomplish:
if($_SESSION['user_type']=="student" || $_SESSION['user_type']=="corporate" || $_SESSION['user_type']=="institute") {
echo '<a href="my-profile.php"><input type="button" value="VISIT YOUR PROFILE"></a>';
}
else {
echo '<a href="signup.php"><input type="button" value="REGISTER NOW"></a>';
}
If user_type
is student, corporate or institute they will be able to visit their profile through the available button. Anyone else will see the register button.
While you're question is not very well put, i think you're asking for this?
$sessionValid = ($_SESSION['user_id'] ? ($_SESSION['user_type'] == "student" ? true : ($_SESSION['user_type'] == "corporate" ? true : ($_SESSION['institute'] ? true : false) : false ) : false ) : false)
if ( $sessionValid )
{
//No login needed
} else {
//Register today!
}
<?php if (isset($_SESSION["user_id"])): ?>
// Logged-in users
<?php if (isset($_SESSION["user_type"]) && $_SESSION["user_type"] == "student"): ?>
// student
<?php elseif (isset($_SESSION["user_type"]) && $_SESSION["user_type"] == "corporate"): ?>
// corporate
<?php elseif (isset($_SESSION["user_type"]) && $_SESSION["user_type"] == "institute"): ?>
// institute
<?php endif; ?>
<?php else: ?>
// REGISTER NOW
<?php endif; ?>