Jump to content

Explode Function


tberger

Recommended Posts

I want PHP to read data I have stored in a text file to pull out certain pieces of data.  Right now when you log in - I want it to check my user text file to determine if the data is there.  If so, I want the page to welcome the person - if not to let them know there is no match.

 

Right now the page always returns no matches and I think it is in the function.  I believe it is how the function is reading the file.  I think if I explode the data in the text file, I might get it to work properly but i am not sure how.  The current function is:

 

<?php

function getLogin($username, $password)

{

 

$email = trim($_POST['email']);

$pass = trim($_POST['pass']);

 

$file = "/staff/seebetra/homepage/ciss225/registered_users.txt";

$lines = file($file);

$logged = FALSE;

foreach($lines as $line)

{

if(preg_match("/^.+?:.+?:".preg_quote($email).":".preg_quote($pass)."$/s", trim($line)))

{

list($first, $last, $f_email, $f_pass) = explode(":", trim($line));

echo "Hello ".$first." ".$last."!";

$logged = TRUE;

break;

}

}

if(!$logged)

echo "Sorry, you didn't match!";

}

?>

 

Is there a way to explode on the text file instead to find the match?

 

I appreciate any help I can get on this.

Link to comment
https://forums.phpfreaks.com/topic/43366-explode-function/
Share on other sites

i think you need to change this:

function getLogin($username, $password)
{

$email = trim($_POST['email']);
$pass = trim($_POST['pass']);

 

to this:

function getLogin($username, $password)
{

$username = trim($_POST['email']);
$password = trim($_POST['pass']);

Link to comment
https://forums.phpfreaks.com/topic/43366-explode-function/#findComment-210610
Share on other sites

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.