Jump to content


Photo

plz.....login script


  • Please log in to reply
5 replies to this topic

#1 honeyboy_20

honeyboy_20
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 22 September 2006 - 07:57 PM

hi guys,
login script doesn't give me result but not give me error
ans considt of 5 file
login.php
logout.php
register.php
main.php
entrance.html

=====================================================================
login.php
=====================================================================
<?php
/* ===========================================================================*/
/*                                                                            */
/*    login.php                                                               */
/*    (c) 2006 Author :ahmed rabie elbohoty                                   */
/*                                                                            */
/*   Description :login file which recieve username and password from user    */
/*     and if it correct redirct user to main page                            */
/* ===========================================================================*/

session_start();
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>login</title>

</head>
<body>
<h2><b>login</b></h2>

<?php
  //____________________________________________________________________________

    $host="";                //the name of localhost
    $user_db="";            //the name of user admin for database
    $password="";          //the name of password admin for database
    $database="userlist"; //the name of database
    $table="users";      //the name of table
 //_____________________________________________________________________________

$links="<a href='main.php'>click here to go to main page</a><br><br>";

// if uou delivre username and password from user
if($user&&$pass)
{//start
    if($logged_in_user==$_get['user'])
    {
    echo $user.",You are already logged in<br><br>";
    echo $links;
    exit;
    }

    //connect to database
    $connect=mysql_connect($host,$user_db,$password)or print"Unable to Connect<br>";
    //select dtabase
    mysql_select_db($database,$connect);
    //re
   $result = mysql_query("SELECT * FROM $table WHERE name LIKE '$user' AND password LIKE PASSWORD('$pass') ");
    //we can make name='$user' in stead of name LIKE '$user'
    //PASSWORD is afunction
     if(!$rsult){
         echo"sorry..we can not enter your details";
         exit;
     }
     if(mysql_num_rows($result)>0)
     {
       $logged_in_user=$_get['user'];
       session_register("logged_in_user");
       echo"Welcome".$logged_in_user."<br><br>";
       echo"$links";
       exit;
   }
   elseif($user||$pass){
       echo"plz fill in both fields<br><br>";
   }
   else{
       echo"invalid login..plz try again<br><br>";
   }
}//end
?>
<form method=post action="login.php">
Your Username
<input type=text name="user" maxlength=20 size=20>
<br>
Your Password
<input type=text name="pass" maxlength=10 size=20>
<br>
<input type=submit value="login">
</form>
</body>
</html>


===================================================
logout.php
===================================================
<?php
session_start();
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>LogOut</title>
</head>
<body>
<h2>LogOut</h2>
<?php
if($logged_in_user){
    session_unregister("logged_in_user");
    echo"<b>You Are Logged Out..Now</b> ";
   }else{
       echo" <b>You haven't logged out yet</b>";
  }
?>
<br> <br>
<a href="login.php">Click Here To Be login<br><br></a>
<a href="register.php">Click Here To register As Anew User<br></a>

</body>
</html>

=================================================


#2 honeyboy_20

honeyboy_20
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 22 September 2006 - 08:00 PM

register.php
=================================================
<?php
/* ===========================================================================*/
/*                                                                            */
/*    login.php                                                              */
/*    © 2006 Author :ahmed rabie elbohoty                                  */
/*                                                                            */
/*  Description :registerfile :user fill the details                        */
/*    to be memmber in our site                                              */
/* ===========================================================================*/

session_start();
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>register</title>
</head>
<body>
<table border=1 cellspacing=1 cellpadding=10 width=50>
<td><h2 align="center">register</h2></td>
</table>
<?php

  //____________________________________________________________________________

    $host="";                //the name of localhost
    $user_db="";            //the name of user admin for database
    $password="";          //the name of password admin for database
    $database="userlist"; //the name of database
    $table="users";      //the name of table
 //_____________________________________________________________________________

     //user must enter all fields to be register
     if($user &&$pass)
     {
    //connect to database
    $connect=mysql_connect($host,$user_db,$password)or print"Unable to Connect<br>";
    //select dtabase
    mysql_select_db($database,$connect);

    /*we must make query in database to ensure that the name which user enter is not found
    so user can register with the new name and we can increase this proceess if we take his mail
    and make check also*/
    
    $result = mysql_query("SELECT * FROM $table WHERE name LIKE '$user'");
    
    //so we will make condition now for the process check
    if(mysql_num_rows($result)==0)
    {
     $result=mysql_query("INSERT INTO $table(name,password)VALUES('$user',PASSWORD('$pass')");
    }
    //if user input is true
    if($result)
    {
       $logged_in_user=$user;
       session_register("logged_in_user");
       echo("Your details Has been added to database<br><br>");
       echo("<a href='main.php'>click here to go to main page</a><br><br>");
       echo("<a href='logout.php'>Click Here To Be logout<br><br></a>");
}
elseif($user||$pass){
    echo"please fill all fields<br><br>";
}else{
    echo"the username has been taken before...plz chosse another name<br><br>";
}
}
?>
<form method=post action="login.php">
Please enter Username
<input type=text name="user" maxlength=20 size=20>
<br>
Please enter Password
<input type=text name="pass" maxlength=10 size=20>
<br>
<input type=submit value="login">
</form>
</body>
</html>
==========================================================
main.php
==========================================================
<?php

/* ===========================================================================*/
/*                                                                            */
/*    login.php                                                               */
/*    (c) 2006 Author :ahmed rabie elbohoty                                   */
/*                                                                            */
/*   Description :login file which recieve username and password from user    */
/*     and if it correct redirct user to main page                            */
/* ===========================================================================*/

session_start();
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>Main</title>
</head>
<body>
<h2>main</h2>
<?php
 if(!$logged_in_user){
     echo"there has been an error.<br><br>";
     echo"<a href='login.php'>Click Here To Be login<br><br></a>";
 }else{
     echo"Welcome".$logged_in_use.".<br>";
 }
?>
</body>
</html>
====================================================================
entrance.html
====================================================================
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>entrance</title>
</head>
<body>
<h2>Entrance</h2>
<br>
<br>
<a href="login.php">Click here to log in </a>
<br>
<br>
<a href="register.php">Click here to register as a new user</a>

</body>
</html>




#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 22 September 2006 - 08:43 PM

try this

http://www.phpfreaks...orials/40/0.php
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 honeyboy_20

honeyboy_20
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 23 September 2006 - 03:05 AM

i need to find wat wrong ?

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 23 September 2006 - 04:12 AM

I agree with AdRock. I only looked at the login script and saw all kinds of mistakes. You would be better off just following that tutorial and createing your own member system.

here is a decent login script.

<?php
session_start();
include("db.php");//your database connection file
$username = mysql_real_escape_string(trim($_POST['username']));
$password = mysql_real_escape_string(trim($_POST['password']));

if ((!$username) || (!$password)) {
    if (!$username) {
        $param = "Username, ";
    }
    if (!$password) {
       $param .= "Password, ";
    }
    echo "You did not enter the following required filed(s) " . $param . "please try again.";
    include("your_login_form.html");
    exit();
}
$mdpwd = md5($password);

$sql = sprintf("SELECT COUNT(*) AS `login_match` FROM `your_users_table` WHERE `username`= '%s' AND `password` = '%s'", $username, $mdpwd); 
$res = mysql_query($sql) or die(mysql_error());
$login_match = mysql_result($res, 0, 'login_match');

if ($login_match > 0) {
    echo "Your username and password do not match";
    include("your_login_form.html");
    exit();
}
}else{
   $_SESSION['username'] = $username;
   //you could do another sql query here to set more session variables
}
?>

When I get a chance I will write a register script for you and post it..

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 Guest_hauntmisery_*

Guest_hauntmisery_*
  • Guests

Posted 23 September 2006 - 09:05 AM

Use cookies it will work much beta...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users