Schlo_50 Posted April 17, 2007 Share Posted April 17, 2007 Hey guys! I am in need of some help with creating a backend control panel so that i can login and update my website with new news etc. Using MySQL to store login credentials is not an option therefore i want to have a script that allows me to login to the control panel on the basis that 'if the username and password entered by myself matches the username and password stored in the script' then the login attempt is successful and the control panel loads (control.php) I am stil learning PHP and this is what i have so far, could someone please revise it and add some code to make my idea work? <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if( ( !$username ) or ( !$password ) ) //Attempted Presence Check if( $username = user2007 ) and ( $password = hey2007 ) //Stored login details that i need to match echo( "Login Succesfull!" ); ?> Thank-you very much! Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/ Share on other sites More sharing options...
ted_chou12 Posted April 17, 2007 Share Posted April 17, 2007 I dont quite understand what your code meant here: <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if( ( !$username ) or ( !$password ) ) //This line will not work, since it doesnt include any sort of processing functions, try this: if ($username == "" or $password == "") {echo "Blank username and password!";} else { if ($username == "user2007") and ($password == "hey2007") {//Stored login details that i need to match echo "Login Succesfull!";}} ?> Ted Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231670 Share on other sites More sharing options...
Schlo_50 Posted April 17, 2007 Author Share Posted April 17, 2007 Thanks but i now have this which is generating the following: 'Parse error: syntax error, unexpected T_LOGICAL_AND in C:\Program Files\xampp\htdocs\testing\control.php on line 30. <html> <head> <title>Control Panel</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <form name="form1" method="post" action=""> <p>South Woodham Ferrers Rotary </p> <p>Control Panel</p> <p>Username: <input type="text" name="user"> </p> <p>Password: <input type="text" name="password"> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html> <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if ($username == "" or $password == "") {echo "Blank username and password!";} else { if ($username == "user2007") and ($password == "hey2007") {//Stored login details that i need to match echo "Login Succesfull!";}} ?> Cheers Ted Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231676 Share on other sites More sharing options...
Schlo_50 Posted April 17, 2007 Author Share Posted April 17, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231699 Share on other sites More sharing options...
rcorlew Posted April 17, 2007 Share Posted April 17, 2007 Replace "and" with "&&" or "|" they will both work Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231706 Share on other sites More sharing options...
MadTechie Posted April 17, 2007 Share Posted April 17, 2007 change code to <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if ($username == "" or $password == "") { echo "Blank username and password!"; }else { if (($username == "user2007") and ($password == "hey2007")) {//Stored login details that i need to match echo "Login Succesfull!"; } } ?> Note the extra bracks (($username == "user2007") and ($password == "hey2007")) Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231718 Share on other sites More sharing options...
Schlo_50 Posted April 18, 2007 Author Share Posted April 18, 2007 Thats brilliant guys but how do i now make it work so that if what i enter does not match the username and password stored in the script it doesn't login? <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if ($username == "" or $password == "") { echo "Please Enter Login Credentials!"; }else { if (($username == "user2007") && ($password == "hey2007")) {//Stored login details that i need to match echo "Login Succesfull!"; } } ?> Thanks for your patience! Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231936 Share on other sites More sharing options...
chronister Posted April 18, 2007 Share Posted April 18, 2007 <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if ($username == "" or $password == "") { echo "Please Enter Login Credentials!"; }else { if (($username == "user2007") && ($password == "hey2007")) {//Stored login details that i need to match echo "Login Succesfull!"; } // added the else statement below else { echo 'Username Or Password Does Not Match, Please Try Again'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231940 Share on other sites More sharing options...
Schlo_50 Posted April 18, 2007 Author Share Posted April 18, 2007 I have entered that however if i test the form with incorrect username and password (not user2007 and pass: hey2007) then the control panel still loads. <html> <head> <title>Control Panel</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <form name="form1" method="post" action="panel.php"> <p>South Woodham Ferrers Rotary </p> <p>Control Panel</p> <p>Username: <input type="text" name="user"> </p> <p>Password: <input type="password" name="password"> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html> <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if ($username == "" or $password == "") { echo "Please Enter Login Credentials!"; }else { if (($username == "user2007") && ($password == "hey2007")) {//Stored login details that i need to match echo "Login Succesfull!"; } else { echo 'Username Or Password Does Not Match, Please Try Again'; } } ?> Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231944 Share on other sites More sharing options...
chronister Posted April 18, 2007 Share Posted April 18, 2007 You have the form submitting to the panel, you need to submit it to itself to process and then redirect if the username and pass is valid... <?php $username = $_POST['user']; $password = $_POST['password']; $self = $_SERVER['PHP_SELF']; if ($username == "" or $password == "") { echo "Please Enter Login Credentials!"; }else { if (($username == "user2007") && ($password == "hey2007")) {//Stored login details that i need to match header('Location:/panel.php'); } else { echo 'Username Or Password Does Not Match, Please Try Again'; } } ?><html> <head> <title>Control Panel</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>"> <p>South Woodham Ferrers Rotary </p> <p>Control Panel</p> <p>Username: <input type="text" name="user"> </p> <p>Password: <input type="password" name="password"> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html> I moved the php above the html so the header redirect did not throw out errors. It works, I tested it. Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231945 Share on other sites More sharing options...
Schlo_50 Posted April 18, 2007 Author Share Posted April 18, 2007 Thank-you, works fine now! I was thinking about placing the code above the html, but never actually tried it. Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231948 Share on other sites More sharing options...
chronister Posted April 18, 2007 Share Posted April 18, 2007 You can also do something like this... this assumes your submit button is called submit <?php if(!$_POST['submit']) // if $_POST['submit'] does not exist { ?> <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>"> Username: <input type="text" name="user"><br /> Password:<input type="password" name="password"><br /> <input type="submit" name="Submit" value="Submit"> </form> <?php } else // else, it does exist therefore the form has been submitted so process form { echo 'Processing Form'; } ?> This is a way to verify whether or not the form has been submitted, and what to do if it has or has not. Handy way to keep the form and processing for said form on one page. I believe that you can do the header redirect in the processing part without generating the "Cannot Modify Headers......." error. I don't remember if I have tried that or not but there is nothing being outputted if the form has been submitted, so I think that would work Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231951 Share on other sites More sharing options...
rcorlew Posted April 18, 2007 Share Posted April 18, 2007 You may want to use sessions in your control panel if you are not already doing so. They are easy to use and a fairly powerful way to check variables if they exist. That way you would have to login before going to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-232163 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.