freemancomputer Posted February 22, 2012 Share Posted February 22, 2012 I am trying to change my web site to user only to public view. I still need users to be able to log in so they can edit things. I did a quick fix to allow everyone to view things by removing the ! from the sessions. How ever with that when i try to log in it just loops to login.php. There are links on the page that only admins will be able to see. Here is my session with the removed !. <?php session_start(); if($_SESSION['login']){ $_SESSION['rank']; $_SESSION['loggedinusername'] = $loggedinusername; $_SESSION['loggedinuseremail'] = $loggedinuseremail; header("location:login.php"); } $rank=$_SESSION['rank']; $loggedinusername=$_SESSION['loggedinusername']; $loggedinuseremail=$_SESSION['loggedinuseremail']; ?> How would i got about allowing eveyone to see this page but the log in still work? If you need anymore code let me know Thank you Quote Link to comment https://forums.phpfreaks.com/topic/257574-login/ Share on other sites More sharing options...
scootstah Posted February 22, 2012 Share Posted February 22, 2012 Remove the whole if statement. Quote Link to comment https://forums.phpfreaks.com/topic/257574-login/#findComment-1320240 Share on other sites More sharing options...
AyKay47 Posted February 23, 2012 Share Posted February 23, 2012 The logic for removing the negation operator makes no sense, if a user has logged in then why would they need to be directed to the login.php page again. Really, either you require a login or you don't. If you want users who are logged in to have certain privileges over the guests, then that is a different story. With this said, login would be optional, and since you have not posted your login script I do not know what $_SESSION['login'] actually holds. But to give you a raw answer, the logic should be that a user should only be redirected if they attempt to login and fail. Again, using the logic you have stated, logging in is optional. Here is a skeleton of what I am talking about: session_start(); if(!isset($_SESSION['login'])) //depends on the logic of setting this value { //add whatever error handling you want header("Location: login.php"); } //proceed with normal code this will not affect guests, who will not have to login to view the page. Quote Link to comment https://forums.phpfreaks.com/topic/257574-login/#findComment-1320291 Share on other sites More sharing options...
jbonnett Posted February 23, 2012 Share Posted February 23, 2012 You will need something of the sort: session_start(); if($_SESSION['loggedIn']){ header(location:); }else{ header(location:); Quote Link to comment https://forums.phpfreaks.com/topic/257574-login/#findComment-1320323 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.