Jump to content

[SOLVED] Quick Question


TheJoey

Recommended Posts

Basically it takes $input, then it gets EVERYTHING from the beginning of the $input up until stop. It then stores that in the array $find.

 

You may not believe it, but regex is one of the most powerful tools of PHP. You should look into these links

 

http://au2.php.net/preg_match

http://au2.php.net/preg_match_all

http://au2.php.net/preg_replace

http://www.regular-expressions.info/

thank you

when i tried impletmenting this into my code i got this.

Warning: preg_match() expects parameter 2 to be string, array given in C:\xampplite\htdocs\Trial\New Folder\examplelogin1\php.php on line 7

 

line 7 being

preg_match('~^(.+)||~', $lines, $find)

$lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array
$find = "$username:$password"; // form a string like you expect it to be in the array
preg_match('~^(.+)||~', $lines, $find);

Yeh ofcourse sorry about not posting thought i did.

<?php 
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$lines = file("users.txt",FILE_IGNORE_NEW_LINES); // read the lines into an array
$find = "$username:$password"; // form a string like you expect it to be in the array
preg_match('~^(.+)||~', $lines, $find);
if(in_array($find,$lines)){
   $_SESSION['logged_in'] = true;
   echo 'Logged in';
} else {
   echo 'You entered a wrong password';
}
?>

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.