Jump to content

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';
}
?>

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.