runnerjp Posted May 9, 2008 Share Posted May 9, 2008 at the moment i use this to restirct only let logged on people to view the page <?php if($logged[username]) { //Logged in code }else { //Not logged in code } ?> but i was wondering if there was a better way of doing this? Link to comment https://forums.phpfreaks.com/topic/104858-solved-restricting-access/ Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 I personally use sessions to do this... and use the item 'intime'... I also use a switch thus keeping all my pages in one file... to make it easier I use smarty as my template engine... but i do something like this.. <?php $login = ''; $_action = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; // get the action from the browser if ($_action != 'logout' && $_action != 'login') { // make sure they arent logging in or logging out. if (!isset($_SESSION['admin']['intime'])) { // session isnt started $interface = 'login.tpl'; // show smarty template login.tpl $aws->assign('errMsg', 'ERROR: You must be logged in, in order to access the administration panel'); // my own class that extends smarty assign the error message. } elseif ($_SESSION['admin']['intime'] < time() - 1800) { // check if intime is current time - 1800 seconds. $interface = 'login.tpl'; // show smarty template login.tpl $aws->assign('errMsg', 'ERROR: Session expired. Please login again.'); // assign error message } } else { $interface = 'constructor.tpl'; switch($_action) { default: break; case login: break; case logout: break; } } ?> Thats just basic how I do mine. Link to comment https://forums.phpfreaks.com/topic/104858-solved-restricting-access/#findComment-536730 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 humm ok is there away where i can do display page if not display error rather then directin to just 1 template Link to comment https://forums.phpfreaks.com/topic/104858-solved-restricting-access/#findComment-536772 Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 Absolutely. It's basically the same thing... except for in the place of $interface and $aws->assign you'd use like echo "You are not logged in" and then in the else is where your page would be... then you might think about using, a header and footer php file for your template, so in each case you can include('header.php'); then do all of your code, then at the bottom include footer.php... Link to comment https://forums.phpfreaks.com/topic/104858-solved-restricting-access/#findComment-536833 Share on other sites More sharing options...
947740 Posted May 9, 2008 Share Posted May 9, 2008 Whenever they login, I just set a session variable: $_SESSION['loggedin'] = "true". I then check whether or not $_SESSION['loggedin'] == "true". Link to comment https://forums.phpfreaks.com/topic/104858-solved-restricting-access/#findComment-536917 Share on other sites More sharing options...
ohdang888 Posted May 9, 2008 Share Posted May 9, 2008 if(isset($logged[username])){ show code }else{ echo 'you must be logged in to see this'; die(); } Link to comment https://forums.phpfreaks.com/topic/104858-solved-restricting-access/#findComment-536965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.