rallokkcaz Posted May 3, 2007 Share Posted May 3, 2007 if wanna make it so if the user "admin" can only view a page without the whole system of 1s and 2s in the data base would the code be something like: if (isset($_session['username'] = 'admin')) { } else { } Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 Please elaborate on your question. I don't quite get what you're asking. If you want an admin to log in first, use sessions. Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted May 3, 2007 Author Share Posted May 3, 2007 i wann make it so only the user admin can view the page, and if your not admin then it sends you somewhere else. Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 You should make a login page, and use sessions to validate the user (which I think you're doing). Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 3, 2007 Share Posted May 3, 2007 you should perhaps look at storing a user level with each user adn this turorial is excellent for developing an access level system. http://www.phpfreaks.com/tutorials/151/1.php dont' be put off - read it a couple of times and you will see that its not anywhere near as difficult as you may think initially. (the last page of the turial will show you how you can use it to allow/deny access to pages based on your login.) Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted May 3, 2007 Author Share Posted May 3, 2007 i do have a login page with sessions and all that stuff its just that all i want is to know how i would make the code i posted above work :-\ Quote Link to comment Share on other sites More sharing options...
brownka Posted May 3, 2007 Share Posted May 3, 2007 At the top of every page (before any php or html code) that you only want the admin user to access put include("adminheader.php"); then the files needed are below. should work fine....ive used it in projects.goodluck! adminheader.php------------------------------------------------------------------------ <?php session_start(); // start session if(!isset($_SESSION['username'] or $_SESSION['username']=='admin')) //check to see if the username is set in the session and if it ='admin' { include("logout.php"); //if its not set or wron user call logout.php exit(); //exit } ?> ---------------------------------------------------------------------------------------- logout.php----------------------------------------------------------------------------- <?php session_start(); session_unset(); //unset any session variable set session_destroy(); //end the session header("location:index.php"); //send them back to the login page or a home page ?> ---------------------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 3, 2007 Share Posted May 3, 2007 if (isset($_session['username']) && strcmp($_session['username'],'admin') == 0) { } else { } Quote Link to comment Share on other sites More sharing options...
brownka Posted May 3, 2007 Share Posted May 3, 2007 spotted an error in my reply....fixed below in the red...sorry At the top of every page (before any php or html code) that you only want the admin user to access put include("adminheader.php"); then the files needed are below. should work fine....ive used it in projects.goodluck! adminheader.php------------------------------------------------------------------------ <?php session_start(); // start session if(!isset($_SESSION['username'] or $_SESSION['username']!='admin')) //check to see if the username is set in the session and if it ='admin' { include("logout.php"); //if its not set or wron user call logout.php exit(); //exit } ?> ---------------------------------------------------------------------------------------- logout.php----------------------------------------------------------------------------- <?php session_start(); session_unset(); //unset any session variable set session_destroy(); //end the session header("location:index.php"); //send them back to the login page or a home page ?> ---------------------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 3, 2007 Share Posted May 3, 2007 mine is more effcient just noted that you have $_session - make sure you use $_SESSION. Quote Link to comment Share on other sites More sharing options...
brownka Posted May 3, 2007 Share Posted May 3, 2007 haha yeah im still learning ToonMariner. Paybe you could help me out with a problem? i have a thread posted..... http://www.phpfreaks.com/forums/index.php/topic,139062.0.html Quote Link to comment 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.