samedi 7 février 2015

Using IF statements based on userid and user logged in

I have a simple website with a profile page for users. When a user logs in, their page is displayed on profile.php a specific user page is access by profile.php?userid=2


I am trying to achieve a set up like this..

Users Logged In can access their profile by: profile.php

profile.php?userid=2


users that are logged out:

profile.php I want to be blank.

and profile.php?userid=2 to still be accessible.


I've managed to get a variation of this working and not working in places.


my code right now to view profiles.



if($_GET['userid']!='') {
$profileuserid=$_GET['userid'];
} else {
$profileuserid=$_SESSION['userid'];
}


To view profile.



<?php if($_SESSION['userid']==$profileuserid){ ?>
//This is where my content goes.
<?php } ?>


Then to try and achieve my goal I was using these.



<?php if(($_GET['userid']==$profileuserid) && ($_SESSION['loggedin'])) { ?>

<?php } elseif((!$_GET['userid']==$profileuserid) && ($_SESSION['loggedin'])) { ?>

<?php } elseif(($_GET['userid']=$profileuserid) && (!$_SESSION['loggedin'])) { ?>

<?php } ?>


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire