Jump to content

Login trouble -- Comparing strings to array elements


jarcoal

Recommended Posts

I'm writing a very simple login system for my blog, and for some reason I can't get this to work.  The text file "bloggerinfo.php" contains the correct login/pass on separate lines (hence the file()).  But even if I type in the right log/pass, $correct seems to always equal 0 by the end, failing the login.  Here is my code so far, thanks for any help:

[code]<?php

$s_name = $_REQUEST["name"];
$s_pass = $_REQUEST["pass"];

$userpass = file('bloggerinfo.php');

if ($s_name == $userpass[0])
{
if ($s_pass == $userpass[1])
{
$correct = 1;
setcookie("blogger", "1", time()+3600);
}
else
{
$correct = 0;
}
}
else { $correct = 0; }
fclose($userpass);
?>

<html>

<body>


<?php
if ($correct == 1)
{
echo "Successful login.  Return to <a href=blog.php>main page</a>.";
}
else
{
echo "Incorrect login.  Return to <a href=login.php>login page</a>.";
}
?>


</body>

</html>[/code]
it's a file that's built by a script for creating users.

here's that code:

[code]$name = $_REQUEST["name"];
$pass = $_REQUEST["pass"];
$email = $_REQUEST["email"];

$bloggerinfo = fopen('bloggerinfo.php', 'a');
fwrite($bloggerinfo, $name. "\n" . $pass . "\n" . $email );
fclose($bloggerinfo);[/code]


so as you can see it just assembles a file with the username on line one, password on line two, email address on line three.

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.