Jump to content

Login Script


TheJoey

Recommended Posts

Im stuck making this login script.

Ive done storing the users on a flat file. Then it recalls only the needed information.

But just then im stuck how do i use the information for a login script

 

Can i use $_POST?

<?php 
$userinfo = file("data.txt");

   echo '<table>';

foreach($userinfo as $key => $val) 
{
   $data[$key] = explode("||", $val);
}

for($k = 0; $k < sizeof($userinfo); $k++);


}

?>

 

Someone suggested

if($d[0] == $username && $d[1] == $password)
{
echo'Loggin successfull' ;

Link to comment
Share on other sites

reading file contents... http://www.tizag.com/phpT/fileread.php

 

The rest is up to you to learn. We can only point you in the right direction. I recommend reading through the PHP tutorials on tizag.com, If anything doesn't make sense look it up on php.net

 

There is some fine examples of how to do various tasks in PHP on the PHP Freaks website.

 

Good Luck :)

Link to comment
Share on other sites

As an example.

 

Username and password combos are stored in a file.

 

foo:bar
bob:whatever
bruce:youok

 

Get you users submitted username and password.

 

$username = $_POST['username'];
$password = $_POST['password'];

 

Now check them against the entires in the file.

 

session_start();
$handle = fopen("users.txt", "r");
$valid = false;
while ($userinfo = fscanf($handle, "%s:%s\n")) {
    list ($name, $pass) = $userinfo;
    if ($username == $name && $password == $pass) {
        $valid = true;
    }
}
fclose($handle);
if ($valid) {
    $_SESSION['logged_in'] = true;
} 
?>

 

Link to comment
Share on other sites

<?php 
session_start();
$handle = fopen("users.txt", "r");
$valid = false;
while ($userinfo = fscanf($handle, "%s:%s\n")) {
    list ($name, $pass) = $userinfo;
    if ($username == $name && $password == $pass) {
        $valid = true;
    }
}
fclose($handle);
if ($valid) {
    $_SESSION['logged_in'] = true;
echo 'yay ur in';
}
else
{
echo 'You entered a wrong password';
}

?>

i added a echo just to test it seems im always entering a wrong password.

 

Link to comment
Share on other sites

<?php 
session_start();
$handle = fopen("users.txt", "r");
$valid = false;
while ($userinfo = fscanf($handle, "%s:%s\n")) {
    list ($name, $pass) = $userinfo;
    if ($username == $name && $password == $pass) {
        $valid = true;
    }
}
fclose($handle);
if ($valid) {
    $_SESSION['logged_in'] = true;
echo 'yay ur in';
}
else
{
echo 'You entered a wrong password';
}

?>

i added a echo just to test it seems im always entering a wrong password.

Link to comment
Share on other sites

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.