Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:39:23+00:00 2026-06-04T14:39:23+00:00

this is a PHP related question. I have searched far and wide for a

  • 0

this is a PHP related question.

I have searched far and wide for a solution to the following but did not find something that worked for me. If someone could help me, would be very much appreciated.

The idea that I have is to create a login page where, if a “specific” pre-determined registration number is given/sent to the user, the visits the login page and the number(s) exists in the file, to execute / login rights allowed.

For example, if a user’s registration number is 12345 while another is 123, would like to first search to see if the user’s number exists, then do something().

Therefore, searching for “12345” would not be the same if “123” exists already as would be the same for “234”, so it has to find a specific number or numbers.

If it makes a difference, there stands to be a “space” before and/or after the number(s).

This would be in an existing file.

Code:

<?php 
$filename = 'datafile.txt'; 

// Data file may contain the following number(s) or any other 
// 123 (no) 
// 1234 (match) 
// 12345 (no) 
// 123456 (no) 
// exact match needed to proceed to page fopen($filename); 
$searchfor = '1234'; 

// this needs to be a variable 
// I don't know what the number will be used. 
$file = file_get_contents($filename); 

if (preg_match($file, $searchfor)) {
  echo "Match found. Proceed to the page."; 
} else { 
  echo "Match not found. Try again."; 
} 

fclose($filename); 
?>

Thank you. Any help is appreciated, cheers.

Fred

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:39:24+00:00Added an answer on June 4, 2026 at 2:39 pm

    Storing these in a flat-file is probably not the way I would do this, but if I were to use a flat-file, the following example should work just fine:

    $nums = "12345 34 45 12345 23"; # use file_get_contents to load from file
    $uNum = 34;
    
    if ( preg_match( "/[^0-9]{$uNum}[^0-9]/", $nums ) ) {
      echo "Access";
    } else {
      echo "Denied";
    }
    

    As for populating the $nums string, you could use file_get_contents() to pull in the contents of your file containing all of the numbers.

    /         Denotes start of pattern
    [^0-9]    Space in pattern cannot be occupied by any number
    {$uNum}   User number - 34 in the example above
    [^0-9]    Space in pattern cannot be occupied by any number
    /         Denotes end of pattern
    

    Essentially, our number will not be found if it has a number on either side of it rather than a space, or nothing at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched related questions to this, but most of them are related to
[This question is somewhat related to this question , but the answers are not...]
Stack Overflow offers related questions (on the right side of this question). I have
So, I think that I have asked this question and others related to it
This question is related to a similar case, namely Removing inline styles using php
This question is related to a previous question I asked, but it's a different.
note: this question is related to PostGIS and Postgresql and is implemented with PHP
I've searched before asking this question. The answered ones were related to Linux hosting
I've searched plenty on this topic and have gotten a lot of good (but
i have a PHP/mySQL question related to virtuemart ecommerce - I've asked on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.