php login page code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ara
Forum Newbie
Posts: 5
Joined: Wed May 21, 2014 1:14 am

php login page code

Post 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.
Last edited by Celauran on Wed May 21, 2014 7:25 am, edited 1 time in total.
Reason: Please use syntax tags around your code.
ara
Forum Newbie
Posts: 5
Joined: Wed May 21, 2014 1:14 am

Re: php login page code

Post 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!!
ryancody
Forum Newbie
Posts: 14
Joined: Wed May 21, 2014 1:48 am

Re: php login page code

Post by ryancody »

Also include validations to the input that will be entered by the user.
ara
Forum Newbie
Posts: 5
Joined: Wed May 21, 2014 1:14 am

Re: php login page code

Post by ara »

sorry.. but what do you mean by validation to the input?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php login page code

Post by Celauran »

ara wrote:login page is not working
Can you be more specific? What errors are you seeing?
ethan9355
Forum Newbie
Posts: 1
Joined: Thu May 22, 2014 1:57 am

Re: php login page code

Post 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.
ryancody
Forum Newbie
Posts: 14
Joined: Wed May 21, 2014 1:48 am

Re: php login page code

Post by ryancody »

Nice concise information on coding of login page.
ara
Forum Newbie
Posts: 5
Joined: Wed May 21, 2014 1:14 am

Re: php login page code

Post 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?
Post Reply