Jump to content

[SOLVED] Help With Loading Data from A TXT


abeisgreat

Recommended Posts

Ok im trying to make a real simple login script.

This is what i have so far.

 

1) a script that posts the username and pass you enter.

 

2) this script in login.php:

 

<?php

$post_user = $_POST['username'];
$post_pass = $_POST['password'];
$userFile = ($post_user . '.php');
list($passmd5);
if ( md5 ($post_pass) == $passmd5 )
{				
echo "Logged In"
}else{
echo "Not Logged In"
}

echo "Test"
?>

 

3) a file named like...

 

dream.php (dream being the username)

and the file contains:

 

<?php die ('You may not access this file.'); ?>
54c280558263a67e0a84ba34f625c464

so a die command than a MD5 of the users password.

 

When i try this code nothing happens. Any help please?

Link to comment
https://forums.phpfreaks.com/topic/79484-solved-help-with-loading-data-from-a-txt/
Share on other sites

Thats on a separate page.

 

Here what index.html is:

 

<div id="login">
<font size="1">
<form action="login.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
<input type="submit" value="Login"/>
</form>
</font>

You have this statement

<php
list($passmd5);
?>

that doesn't make a whole lot of sense.

 

Where is the variable $passmd5 set?

 

You set the variable $userFile to string containing the filename, but you never do anything with it.

 

Ken

Ya.. I have never done php before so i was trying to get something to work so apparently in my attempt for anything I must have really screwed up that code. So that could be a big problem in my code.

 

I know $userFile needs to get loaded then $passmd5  is the second line in the $userfile

 

But i havnt the slightest idea how to do that

The simplest way of doing what you want is:

<?php

$post_user = stripslashes($_POST['username']);
$post_pass = stripslashes($_POST['password']);
$userFile = $post_user . '.php';
if (file_exists($userFile)) {
     list($dmy,$passmd5) = file($userFile);
     $passmd5 = trim($passmd5);
     if ( md5 ($post_pass) == $passmd5 )
         echo "Logged In";
    else
         echo "Not Logged In";
} else
     echo "Not Logged In";
echo "Test"
?> 

 

Note: code not checked for syntax errors.

 

Ken

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.