/    Sign up×
Community /Pin to ProfileBookmark

preg_match question

hi i have looked in the php manual and other sources but did not find how to do this

$page = file_get_contents(‘page.txt’);
$str = $_GET[“one”].”|”.$_GET[“two”];

i want to search for one|two in page.txt, i know $str and $page are correctly written, so this leads me to preg_match being wrong

this is what im trying but it doesnt work ?
if (preg_match(“/$str/i”, $page)) {

i have tried several other ways but no luck, whats wrong

Thanks
Rich

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@JonaApr 03.2004 — [code=php]
if (preg_match("/($str)/i", $page)) {
[/code]
Copy linkTweet thisAlerts:
@96turnerriauthorApr 03.2004 — nope no joy ?, im just messing about trying to make a flat file login, i have made a normal login, if ($username = admin) etc and i could set it up for more than one user, but im trying to make it so that users can register ive done the register part and all users are written to users.txt in form

username|password

username|password

.....

now to do the login which im having a bit of trouble

$users = file_get_contents('users.txt');

$str = $_GET["username"]."|".$_GET["password"];

if (preg_match("/($str)/i", $users)) {

echo "You Have Successfully Logged In <b>".$username."</b>";

} else {

echo "Sorry, Your Login Was Unsuccessful, Please Go Back And Try Again";

}

after it is working, i will change echo "you have.... logged in" to a redirect, but for testing purposes im leaving it like that

appreciate your help

o yeah lol i forgot to tell you the problem, i make a user say username rich password rich, and it stores it in users.txt but when i go to login, whatever password is used, it still displays, you have successfully logged in

Rich
Copy linkTweet thisAlerts:
@JonaApr 03.2004 — [font=arial]Then you'll need to escape the pipe.[/font]

[code=php]
$str = $_GET["username"]."\|".$_GET["password"];
[/code]
Copy linkTweet thisAlerts:
@96turnerriauthorApr 04.2004 — thanks for that always forget to escape :mad:
Copy linkTweet thisAlerts:
@JonaApr 04.2004 — [font=arial]It's a long process to learn RegExps... I haven't even learned them as well as some have - namely pyro and Jeff Mott.[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@96turnerriauthorApr 04.2004 — ok well im way off being in their league in terms of php, but one day soon, maybe just maybe
Copy linkTweet thisAlerts:
@JonaApr 04.2004 — [i]Originally posted by 96turnerri [/i]

[B]ok well im way off being in their league in terms of php, but one day soon, maybe just maybe [/B][/QUOTE]


[font=arial]"You can do anything if you put your mind to it." ?

I'm fifteen, and I've learned a lot. True, I'm nowhere near as good as they are, but I've got time. I recently got an electric guitar, and have started practicing it. I'm terrible, but my dad is really good, and if I work at it as hard as I worked at learning to program, I'll be a decent guitar player soon. Just keep at it. ?[/font]
Copy linkTweet thisAlerts:
@96turnerriauthorApr 04.2004 — i will you get a feeling o self satisfaction when you learn something and get it too work by yourself, but when i get stuck in turn to hear
Copy linkTweet thisAlerts:
@JonaApr 04.2004 — [i]Originally posted by 96turnerri [/i]

[B]i will you get a feeling o self satisfaction when you learn something and get it too work by yourself, but when i get stuck in turn to hear [/B][/QUOTE]


[font=arial]When I get stuck, I usually head over to good ole' PHP.net and look up a bunch of stuff. If I can't figure it out, I'll come here and search the forums. When all else fails, I ask. :p But that's just me, independent and self-sufficient (or so I'd like to think sometimes). :rolleyes: [/font]
Copy linkTweet thisAlerts:
@96turnerriauthorApr 05.2004 — yes i check out php.net too before coming here, but its had to find what your looking for, you know what you want to do, but cant find the function, about a week ago i downloaded the manual and that comes in handy, cos you can search easier too
×

Success!

Help @96turnerri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...