Jump to content


Photo

Login script...


  • Please log in to reply
7 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 May 2006 - 12:18 AM

I need a login script, I finally got my registration working..it uses md5 encryption. So I'll need a user and pass field and it has to change to md5 before it goes through to the database. I need it to use cookies and I would prefer only 1 cookie be set upon login. I have absolutely no idea how to go upon this...

table name - users
connect - inc/connect.php
row - username
row - pass

If someone could just give me the basic maybe I could try and get it working and post back for help.

Thanks!

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 29 May 2006 - 12:42 AM

have a look for the set_cookie function - its dead easy
follow me on twitter @PHPsycho

#3 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 29 May 2006 - 12:52 AM

[!--quoteo(post=377936:date=May 28 2006, 07:18 PM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 07:18 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I need a login script, I finally got my registration working..it uses md5 encryption. So I'll need a user and pass field and it has to change to md5 before it goes through to the database. I need it to use cookies and I would prefer only 1 cookie be set upon login. I have absolutely no idea how to go upon this...

table name - users
connect - inc/connect.php
row - username
row - pass

If someone could just give me the basic maybe I could try and get it working and post back for help.

Thanks!
[/quote]

Id recommend sessions! there easier!...lol....
"Syntax error" .. WHERE THE **** IS IT?!

#4 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 May 2006 - 12:57 AM

What are the advantages and disadvantages between sessions and cookies?

I'm still new to PHP...so by looking up some cookie stuff I was able to code this...but I know it won't work I just need to know what I have to do to make it work...


<?php

include('inc/connect.php');

$uname = $_POST['uname'];
$pass = $_POST['pass'];

$chkpass = md5($pass);

$query = "SELECT * FROM users WHERE username==$uname"
$result = mysql_query($query) or die('Failed to connect to user database');

$value = '$_COOKIE["Pranksters"]';

setcookie("Pranksters", $value);


?>



#5 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 May 2006 - 02:44 AM

Anybody?

EDIT - I've added the form on the bottom, code here:

<style type="text/css">
<!--
.style3 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: x-small;
}
-->
</style>

<span class="style3">Username: 
<input type="text" name="uname">
<br>
Password: 
<input type="password" name="pass">
<br>
<input type="submit" name="submit" value="Login">
</span>


#6 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 May 2006 - 10:09 AM

bump

#7 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 May 2006 - 12:29 PM

Here's my current code:

<?php
session_start();
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login - Pranksters</title>
<style type="text/css">
<!--
.text {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: x-small;
    color: #666666;
}
#form1 #username {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #666666;
}
body,td,th {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="59%" border="0" cellspacing="3">
    <tr>
      <td>Username:
        <br />
        <input name="username" type="text" id="username" /></td>
    </tr>

    <tr>
      <td>Password:      
        <br />
        <input name="password" type="password" id="username" />
      <br />
      <span class="text">
      <input name="remember" type="checkbox" id="remember" value="yes" />
Keep me logged in on this computer </span>      <br /></td>
    </tr>
    <tr>
      <td><input name="Login" type="submit" id="username" value="Submit" /></td>
    </tr>
    <tr>
      <td><?php
    
    //Include Connection File
    include('inc/connect.php');
    
    //If login is pressed
    if(isset($_POST['Login']))
    {
        // Get the user info
        $username = strip_tags($_POST['username']);
        $password = strip_tags($_POST['pass']);
        $user = addslashes($username);
        $pass = addslashes($password);
        $md5pass = md5($pass);
        
        // Get the date
        $date = date("d/m/y");
        
        // See if they are in the databse
        $query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `pass` = '$md5pass' LIMIT 1") or die(mysql_error());
        
        if(mysql_num_rows($query) >= "1")
        {
            
                    // Cookie is equal to 10 years
                    setcookie("loggedin", "$username", time()+60*60*24*365*10, "/", "thecodingplace.com", 0);
            
            header("Location: index.php");
        }
        else
        {
            echo 'Not logged in';
        }
    }  
?></td>
    </tr>
  </table>
</form>
</body>
</html>



problem is, it sets the cookie but says not logged in, and it doesnt redirect...help?

#8 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 May 2006 - 02:13 PM

anyone? i really need the login and logout done.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users