php checking if 2 contents match

⚠️
Self Deleted
Joined
Oct 20, 2009
Messages
241
Reaction score
9
ive read on this a bit but still not sure

can u do it like this?

if something==something then its a match?

works like that? or do action if the 2 contents match

if something==something then GO

or how u do with php :D ?
 
I guess you could do a simple if/else statement.
PHP:
$var1 = 1;
$var2 = 2;

if($var1 == $var2){
  echo "Success";
}else{
  echo "Fail";
}
Keeping it the way it is, the code will fail. Changing them both to the same number, or the like, will result in success. With PHP, the two equal signs '==' basically means 'Equals'. Var1 must be equal to Var2 if you're wanting success.

I don't know a better way of explaining it.
 
ok thnx :P

what if i have sumtin like this

$file = fopen("file.txt", "r");
if ($_POST["data"] == $file){
echo "ok";
}

i have this and dun work.. gives error
like its not "ok"; ;/
 
that means $file is not equal to $_POST['data']

Maybe you should ouput the two variables that aren't equal using var_dump(), and find out why.

Read the manual for fopen() and keep testing, checking the manual, and coding repeatedly until it works.
 
using var_dump() tells me that both of them are same variables :)
string(3)123
both
and im using "r" to read file from start .. anything wrong with that?
coding for hour this one thing ..... :D
 
What are you using this for, exactly?
 
i got input form
i enter some data into input
then click ok and
php file reads the specific file
if inputed data is same as the data in the text then pass

anything?

ok so
if i use
$var1 = fopen() //this suposed to get "123"
$input = $_POST["input"];

if ($input == "123")//this ok but if i use other one
if ($input == $var1)//this dont work...they dont match this way lol
 
using var_dump() tells me that both of them are same variables :)
string(3)123
both
and im using "r" to read file from start .. anything wrong with that?
coding for hour this one thing ..... :D

fopen() returns a resource, not a string. And you need to read the file to get the contents.

You can try: var_dump(file_get_contents('./test.txt'));

Code:
string(4) "123
"

As in:
PHP:
php > $file = file_get_contents('test.txt');
php > echo $file;
123
php > echo $file == "123" ? 'yes' : 'no';
no
php > echo $file == "123\n" ? 'yes' : 'no';
yes


Take note that files typically end with an empty line (usually "\n" or "\r\n").

Also take note that \n only works as a new line in double quotes as in:
PHP:
php > echo "\n";

php > echo '\n';
\n
 
Last edited:
I just write all my user's passwords down on my hand with a sharpie... Anyone wanna sign up?

-Signs you sound like someone who will never leak passwords.

OT: I reccommend using mysql/i for storing passwords :D as it isnt hard to find a txt file.
 
Back