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
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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.