Page 1 of 1

php login page code

Posted: Wed May 21, 2014 1:25 am
by ara
please see my login page code. i am stuck here. i want to display a message when a registered user clicks login after submiting the username and password.

Code: Select all

<!DOCTYPE html>
<html>
<title>Log In </title>

<div id="container" style="width:500px">
<div id="header" style="background-color:#C0C0C0;">
<h1> Log In </h1>


<form>
<b>UserName:</b> <input type="text" id="usn" name="username"> <br>
<b>Password:</b> <input type="password" id="pwd" name="pass"> <br>
<input TYPE="BUTTON" VALUE="Login"> <br>

<a href="http://localhost/test/complete_form/registration2.html" target="_blank">User Registration </a> <br> <a href="file:///C:/wamp/www/test/form2.html" target="_blank">Forgot Password </a> <br><a href="file:///C:/wamp/www/test/form4.html" target="_blank">Change Password </a>
</form>
<?php
session_start();

if(isset($_POST["Login"])) {

    header("location: member2.php");

    exit();
}
?>
<?php 
if(isset($_POST['username']) && isset($_POST['pass']))
{
$USN = $_POST['username'];
$PWD = $_POST['pass'];
$myServer = "xxxxxx";
$myUser = "xx";
$myPass = "xxxx";
$myDB = "tab"; 


$conn = new COM ("ADODB.Connection")
  or die("Cannot start ADO");


$connStr = "PROVIDER=SQL Server Native Client 11.0 ;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; 
  $conn->open($connStr); 
$query = "SELECT count(userID) FROM [tab].[dbo].[register1] WHERE username='" . $USN . "' AND pass ='" . $PWD . "'" ;  // query the person

  // ------- MAKE SURE PERSON EXISTS IN DATABASE ---------


$rs = $conn->execute($query);
$num_columns = $rs->Fields->Count();

 

for ($i=0; $i < $num_columns; $i++) {

    $fld[$i] = $rs->Fields($i);

}             

 

while (!$rs->EOF)  //looping through the recordset, until end of file.
{
for ($i=0; $i < $num_columns; $i++)

    {

                if ($i == 0)

                {

                $existCount =  "$fld[$i]" ;           

                }

       

     }

                $rs->MoveNext(); //move on to the next record
///close the connection and recordset objects freeing up resources
}

$rs->Close(); 

  if ($existCount == 1)
{
 $_SESSION['USN'] = $USN;
 $_SESSION['PWD'] = $PWD;

//print $USN;

header("location: member2.php");

exit();
}
else
{
echo 'That information is incorrect, try again <a href="login2.html">Click Here</a>';
exit();
}
}
?>
</html>
********************
member2.php looks like this

Code: Select all

<?php

 if(!isset($_SESSION["username"]))
 {
 header("Location: login2.php");
 }

?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome </title>
</head>
<body>
<h2> This is your login page, welcome <?=$_SESSION['username'];?>!
<p> See your welcome page </p>
</body>
</html>
***************** please help me.

Re: php login page code

Posted: Wed May 21, 2014 1:37 am
by ara
i am new to php coding, i am able to make registration form,, new users are able to login, but login page is not working,, please help me in troubleshooting the code.
thanks in advance!!

Re: php login page code

Posted: Wed May 21, 2014 1:56 am
by ryancody
Also include validations to the input that will be entered by the user.

Re: php login page code

Posted: Wed May 21, 2014 2:09 am
by ara
sorry.. but what do you mean by validation to the input?

Re: php login page code

Posted: Wed May 21, 2014 7:27 am
by Celauran
ara wrote:login page is not working
Can you be more specific? What errors are you seeing?

Re: php login page code

Posted: Thu May 22, 2014 2:03 am
by ethan9355
Thanks for providing such useful information. Recently, I hired outsourceddev.com for developing my website in PHP.
They did a nice job at a very reasonable cost.

Re: php login page code

Posted: Thu May 22, 2014 3:38 am
by ryancody
Nice concise information on coding of login page.

Re: php login page code

Posted: Thu May 22, 2014 4:26 am
by ara
@ryancody..well i think,, there is something missing in this code, cant figure out whats that...? is that the validation thing you mentioned before?