Jump to content

Archived

This topic is now archived and is closed to further replies.

honeyboy_20

plz.....login script

Recommended Posts

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
=====================================================================
[code]<?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>[/code]


===================================================
logout.php
===================================================
[code]
<?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>[/code]

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

Share this post


Link to post
Share on other sites
register.php
=================================================
<?php
/* ===========================================================================*/
/*                                                                            */
/*    login.php                                                              */
/*    (c) 2006 Author :ahmed rabie elbohoty                                  */
/*                                                                            */
/*  Description :registerfile :user fill the details                        */
/*    to be memmber in our site                                              */
/* ===========================================================================*/

[code]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>[/code]
==========================================================
main.php
==========================================================
[code]<?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>[/code]
====================================================================
entrance.html
====================================================================
[code]<!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>[/code]


Share this post


Link to post
Share on other sites
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.

[code]
<?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
}
?>
[/code]

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

Good Luck,
Tom

Share this post


Link to post
Share on other sites
Guest hauntmisery
Use cookies it will work much beta...

Share this post


Link to post
Share on other sites

×

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.