Jump to content

Getting contents from a php file


phpcode

Recommended Posts

I'm storing peoples usernames and passwords in a php file but I've got a problem:

 

<?php


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

$file = "members/" . $username . ".php";

function Login()
{
file_get_contents($file);
if ($password == $pass)
{
echo "Logged in";
} else {
echo "Invalid username and/or password!";
}
}


if (file_exists($file))
{
Login();
} else {
echo "Invalid username and/or password!";
}

?>

 

The file name is the users account name and the password is inside the php file. I use file_get_contents to get the password but I've got a problem. Whenever someone enters their account information everything works apart from checking the users password no matter what password they enter it says they logged in, can anyone see whats wrong with the code above?

 

Contents of the users file:

 

<?php 

$pass = "nxHLS6kM";
$ip = "*";

?>

Link to comment
https://forums.phpfreaks.com/topic/82339-getting-contents-from-a-php-file/
Share on other sites

Because I cannot work mysql:

 

 

<?php
$location = "localhost";
$username = "root";
$password = "******";
$database = "test";

$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");

mysql_query("CREATE TABLE users ( 
    user VARCHAR(20), 
    pass VARCHAR(20))");

$insert = "INSERT INTO users (firstname,surname,location) 
    VALUES ($username,$password)";
    mysql_query($insert) or die ("Could not add data to the table");  


?>

 

And it says "Could not add data to the table" but it can create the database.

Because I cannot work mysql:

 

 

<?php
$location = "localhost";
$username = "root";
$password = "******";
$database = "test";

$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");

mysql_query("CREATE TABLE users ( 
    user VARCHAR(20), 
    pass VARCHAR(20))");

$insert = "INSERT INTO users (firstname,surname,location) 
    VALUES ($username,$password)";
    mysql_query($insert) or die ("Could not add data to the table");  


?>

 

And it says "Could not add data to the table" but it can create the database.

 

 

 

You didnt provide the query with a location.

 

 

 

 

$insert = "INSERT INTO users (firstname,surname,location) VALUES ('$username','$password','$location')";

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.