forms - Accepting login number with changing prefix with PHP -


i have flatfile database file following numbers:

1 2 3 4 5 etc. 

the numbers correspond user id person enter of numbers above, in order login.

i not want modify file. question is, if there's way add accepted "prefix".

for example, user logs in with:

abcd1 abcd2 abcd3 abcd4 abcd5 etc. 

but data file still, not contain prefix "abcd":

1 2 3 4 5 etc. 

it have "perfect" match. tests have done far have not been conclusive

i guess using accepted "array" way go?

my present login php script this, only works on exact match number, add prefix can change later on:

<?php date_default_timezone_set('america/new_york'); $today = mktime(0, 0, 0, date("m"), date("d"), date("y"));  $currenttime = date('h:i:s:u'); list($hrs,$mins,$secs,$msecs) = split(':',$currenttime);  echo "<center><form action=\"" . $php_self . "\" method='post'><input onkeypress=\"return isnumberkey(event)\" type='text' name='unum' /><input type='submit' value='submit' /></form></center>";  if(!$_post['unum']) { die('<center>entrer votre numéro d\'inscription pour finaliser votre demande.</center>'); }  $numbers = file_get_contents("datafile.txt");  $unumber = $_post['unum'];  if ( @preg_match( "/([^0-9]{$unumber}[^0-9])/", $numbers ) ) {  print_r( "<center>the number $unumber good. may proceed.</b><br><br>" );  file_put_contents($_post['unum'].".txt",$_post['unum'] . "\nused on ".date("m/d/y", $today). (" $hrs:$mins:$secs")."");  include 'validate_process.php';  if (isset($_post['unumber'])) {  $unumber = $_get['inscripnum1']; }  } else { echo "<center>sorry, login number not exist.</center>"; }  ?> 

before preg_match, check if input has desired prefix , remove it.

$unumber = $_post['unum'];  $prefix = "abcd"; //you can change prefix anytime $length = strlen($prefix); if(substr($unumber, 0, $length) === $prefix) {     $unumber = substr($unumber,$length); } else {     $unumber = ""; //empty or value not valid id stored in flatfile. }  //now use $unumber in preg_match()  if ( @preg_match( "/([^0-9]{$unumber}[^0-9])/", $numbers ) ) {     //do } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -