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
https://forums.phpfreaks.com/topic/172663-login-script/
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
https://forums.phpfreaks.com/topic/172663-login-script/#findComment-910114
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
https://forums.phpfreaks.com/topic/172663-login-script/#findComment-910151
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
https://forums.phpfreaks.com/topic/172663-login-script/#findComment-910453
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
https://forums.phpfreaks.com/topic/172663-login-script/#findComment-910646
Share on other sites

Archived

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

×
×
  • 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.