Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231670
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231676
Share on other sites

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"))

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231718
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231936
Share on other sites

<?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';

  }

}

?>

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231940
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231944
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231945
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/47469-control-panel/#findComment-231951
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.