unibox Posted March 2, 2010 Share Posted March 2, 2010 I am new to php and I am learning as I go. I have a scholarship application site where I use phpMyEdit to edit the database. I would like to password protect the phpMyEdit.php file. Everything I have tried seems to break phpMyEdit. All of the tutorials or scripts I have found are meant for html pages. I really would like something simple for my skill level. As I progress I can try more complicated protection. If I could get a script with prompt for a password every time I access the phpMyEdit.php that would be fine. If someone could point me in the right direction that would be cool. Thanks Andy Quote Link to comment https://forums.phpfreaks.com/topic/193891-password-protect-phpmyedit/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 In its most basic form, you would simply need to add code like the following to the start of the file - <?php session_start(); // determine if the current visitor is logged in and is permitted to access this page if(!isset($_SESSION['username']) || $_SESSION['level'] != 'admin'){ die('You are not permitted to access this page'); // you could also redirect back to your log in page // don't forget to put a die() statement after any redirect to prevent the remainder of the code on the page from still being executed while the browser requests the new URL. } // the remainder of the code on the page ?> Your log in code would need to correctly start a session and set $_SESSION['username'] and $_SESSION['level'] (you can omit and remove this second variable if YOU are the only person that has a username set up in the log in code.) Quote Link to comment https://forums.phpfreaks.com/topic/193891-password-protect-phpmyedit/#findComment-1020435 Share on other sites More sharing options...
unibox Posted March 2, 2010 Author Share Posted March 2, 2010 Thanks for the reply. I have to admit your code looks self explanatory, I think. It is looking for $_SESSION['username'] if no then it continues to die. I tried searching for a simple login to set username but have to confess I couldn't figure it out. More explanation on my requirements: My problem I guess is. When I use phpMyEdit.php it displays about 15 rows per page. I can get the passowrd protection code I was using to work for the first page but when I use the drop down to select another page it asked for the password and would only display he first page. Even if I select another page. Here was the code I was trying. http://www.zann-marketing.com/sas I like the simplicity. Thanks Again Andy Quote Link to comment https://forums.phpfreaks.com/topic/193891-password-protect-phpmyedit/#findComment-1020567 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 Ummm. To make sure that the code I posted worked before I posted it, I made a test page using phpMyEdit that has 90+ pages. I was able to switch pages, change, delete... while still remaining 'logged in'. We cannot really tell you why what you tried did not work without seeing the actual code that exhibited the symptoms. Quote Link to comment https://forums.phpfreaks.com/topic/193891-password-protect-phpmyedit/#findComment-1020592 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 I tried that script (at the link you posted) and it works as expected. It is cookie based, so if it only worked on the first visit to your page, then either you have disabled cookies in your browser or there is a header() error occurring because something was output to the browser before the cookie, or because the cookie they are using does not set the path or domain portion and something caused the path or domain (actually the subdomain/hostname) to change and the cookie no longer matched the page. Quote Link to comment https://forums.phpfreaks.com/topic/193891-password-protect-phpmyedit/#findComment-1020605 Share on other sites More sharing options...
unibox Posted March 2, 2010 Author Share Posted March 2, 2010 Thanks so much. After reading your last message I found I was putting the sas code in the main phpMyEdit code. I wrapped it in its own php tags and it works like a charm. I really appreciate the help. I know talking to a noob can be a pain. It is hard for me even to ask the question so I don't sound to stupid. I meant no disrespect. I didn't want to say I didnt know how to set up your code. I added your code but is said "You are not permitted to access this page" I know I have to set the username but don't know how. sorry. Thanks again Andy Quote Link to comment https://forums.phpfreaks.com/topic/193891-password-protect-phpmyedit/#findComment-1020637 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.