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

Link to comment
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.

 

 

 

You didnt provide the query with a location.

 

 

 

 

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

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.