CiaranAshton Posted December 19, 2012 Share Posted December 19, 2012 Hi im new to this site. Been coding PHP a little while but still learning. Im writing a simple log in feature to make a website more dynamic. My question is I've written a simple html form and simple php admin page. If I link to another page that I wish for only the admin to see, or back to the original admin page from one of the others It comes up with errors as it wants me to log in again. So I wold like to knwo how to carry the details of the login from one page to another. Im trying to keep it simple as I want to make sure I understand how it all works. Below is the code I wrote for my admin page <Html> <head> <title>Admin Page</title> </head> <body> <?Php include 'config.php'; include 'opendb.php'; $username = $_POST['username']; $password = $_POST['password']; $level = mysql_result(mysql_query("SELECT level FROM users WHERE username='".mysql_real_escape_String($username)."' AND password='".mysql_real_escape_String($password)."'"),0) or die ('<br><br><br><br><b>Incorrect Password or Username'); switch ($level) { case 1: echo ("Hello Admin");break; case 2: echo ("Hello User");break; } ?> </body> </html> Thank you, Ciaran. Quote Link to comment https://forums.phpfreaks.com/topic/272182-storing-user-log-in-details/ Share on other sites More sharing options...
Muddy_Funster Posted December 19, 2012 Share Posted December 19, 2012 What your looking for is a form of what's called "Persistance" and is normaly accomplished by using the built in PHP super-global array $_SESSION. To make this work you must start every page that depends on the user being logged in with <?php session_start(); ... ?> you can then pass information between pages using $_SESSION['your_variable'] = $theVariableToBePassed; to set the session variable and $variableThatHasBeenPassed = $_SESSION['your_variable']; to get it The normal rules apply fore case sensetivity and the such. Quote Link to comment https://forums.phpfreaks.com/topic/272182-storing-user-log-in-details/#findComment-1400310 Share on other sites More sharing options...
CiaranAshton Posted December 19, 2012 Author Share Posted December 19, 2012 Thank you this is great help. Do you know of any example code I could look at to help get my head around this? Quote Link to comment https://forums.phpfreaks.com/topic/272182-storing-user-log-in-details/#findComment-1400322 Share on other sites More sharing options...
Muddy_Funster Posted December 19, 2012 Share Posted December 19, 2012 the PHP manaul page on SESSION would be my reccomended starting location, there are some samples further down the page. Quote Link to comment https://forums.phpfreaks.com/topic/272182-storing-user-log-in-details/#findComment-1400328 Share on other sites More sharing options...
CiaranAshton Posted December 19, 2012 Author Share Posted December 19, 2012 Great thank you for the help working nicely now! Quote Link to comment https://forums.phpfreaks.com/topic/272182-storing-user-log-in-details/#findComment-1400330 Share on other sites More sharing options...
Muddy_Funster Posted December 19, 2012 Share Posted December 19, 2012 no problem Quote Link to comment https://forums.phpfreaks.com/topic/272182-storing-user-log-in-details/#findComment-1400332 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.