Jump to content

Recommended Posts

Some steps to do it:

1-create a form where users will input username and password with submit button.

2-filter users inputs.

3-create a query where you will check the users input with a table in db,that is the data for that username exists or not.

4-if yes,store the username in session and redirect him to another page.

5-if not show him error with login page again.

 

Hope this idea helps.

i have a easy to install php script which does the following:

 

registers accounts (user,password,email,sex,name,ip address)

logs in accounts

admin login to check which ip addresses have been viewing website(will soon have more features)

 

 

u just gota add a few directorys and a few files...   comment me if you want it

 

 

 

Some steps to do it:

1-create a form where users will input username and password with submit button.

2-filter users inputs.

3-create a query where you will check the users input with a table in db,that is the data for that username exists or not.

4-if yes,store the username in session and redirect him to another page.

5-if not show him error with login page again.

 

Hope this idea helps.

 

i made user input form. dont know how to do 2 and 3 step... can you please explain what you mean by filter user input, and provide a query sample aswell if possible (for step 3)

ok.

Form:

<form action='' method='post'>
<input type='text' name ='username'><br>
<input type='password' name='password'><br>
<input type='submit' name='submit' value='login'>
</form>

Now:

<?php
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);

if(isset($_POST['submit'])){
if($username == ''){
echo "Please fill in username field";
}
elseif($password == ''){
echo "Please fill in password field";
}else{
$sql="select username from table where username='$username' and password='$password'";
$q=mysql_query($sql);
$num=mysql_num_rows($q);
if($num < 0){
echo "NO match found";
}else {
$_SESSION['username']=$username;
header('location:index.php');
}
}
}
?>

Make sure you are connected to mysql.

Hope this will helps.

 

Was missing session start.

Updated:

name it as test.php

<?php
session_start();
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);

if(isset($_POST['submit'])){
if($username == ''){
echo "Please fill in username field";
}
elseif($password == ''){
echo "Please fill in password field";
}else{
$sql="select username from table where username='$username' and password='$password'";
$q=mysql_query($sql);
$num=mysql_num_rows($q);
if($num < 0){
echo "NO match found";
}else {
$_SESSION['username']=$username;
header('location:index.php');
}
}
}
?>

 

You can make index.php.

<?php
session_start();
$username=$_SESSION['username'];
if($username != ''){
echo "Hi,you are logged in successfully.";
}
else
{
header('location:test.php');
}
?>

<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "mother";
$db_table = "new_login";

//$created_on = date("U",$timestamp);
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db("rdms",$db);
?>
<html >
<head>

</head>
<link rel="stylesheet" type="text/css" media="screen" href="abc.css" /> 
<body>
<fieldset>
<legend>
Login
</legend>
<img src="header.jpg"
align="top"> 

<?
session_start();
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);

if(isset($_POST['submit'])){
if($username == ''){
echo "Please fill in username field";
}
elseif($password == ''){
echo "Please fill in password field";
}else{
$sql="select username from table where username='$username' and password='$password'";
$q=mysql_query($sql);
$num=mysql_num_rows($q);
if($num < 0){
echo "NO match found";
}else {
$_SESSION['username']=$username;
header('location:index1.php');
}
}
}
?>
<form method="post" action="">

<table width="470">
<tbody>

<tr>
	<td>User Name:</td>
	<td><input type="text" name="$username" class="abc"></td>
</tr>
<tr>	
	<td>Password:</td>
	<td><input type="password" name="$password" class="abc"></td>
</tr>

</tbody></table>
</fieldset>
<br><br>
<input type="submit" name="Submit" value="Submit">
</form>
</html>

index1.php

<?php
session_start();
$username=$_SESSION['username'];
if($username != ''){
echo "Hi,you are logged in successfully.";
}
else
{
header('location:login1.php');
}
?>

here is my piece of code but its not doing anything... can you make appropriate changes for that if login successful, it redirect to another page? (say main.php)

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.