Page 1 of 1

EREG to PREG_MATCH Error

Posted: Sat Jun 12, 2010 6:43 am
by gazzieh
Hi

I have built a system on my localhost, which is running PHP 5.2.1 and mySQL 5.0.33. I have used the following code:

Code: Select all

function validateTextOnly($theinput,$description = '') {
   $result = ereg ("^[A-Za-z0-9\ ]+$", $theinput );
      if ($result) { return true; }
      else {
         $this->errors[] = $description;
	 return false; }}
I have uploaded the site (that works locally) and hit error after error. The first one I realised is that my local mySQL converted my passwords using the PASSWORD() parameter and resulted in letters and numbers. However, my hosted area has the newer PASSWORD() system that adds a * to the front.

I added * to my array for EREG but this still failed. I then realised that EREG has gone and that I should now use PREG_MATCH. However, I tried this:

Code: Select all

$result = preg_match ("/^[A-Za-z0-9\ ]+$*/", $theinput );
This fails everytime, so what am I doing wrong?

My hosted system uses PHP 5.2.13 and mySQL 5.0.90.

***** EDIT ******

Okay, I now realise that I should have used \* rather than * to rule out it's use as a command. However, local is logging in, remote site is not. Any ideas?

Re: EREG to PREG_MATCH Error

Posted: Sat Jun 12, 2010 2:08 pm
by requinix
1. Are you sure the only difference between the two is the added *?
2. What's the rest of your code? Because if there's a problem and it's not with the validator then it must be somewhere else.

Re: EREG to PREG_MATCH Error

Posted: Sat Jun 12, 2010 4:49 pm
by cpetercarter

Code: Select all

$result = preg_match ("/^[A-Za-z0-9 \*]+$/", $theinput );

Re: EREG to PREG_MATCH Error

Posted: Mon Jun 14, 2010 2:55 am
by gazzieh
tasairis wrote:1. Are you sure the only difference between the two is the added *?
2. What's the rest of your code? Because if there's a problem and it's not with the validator then it must be somewhere else.
Thanks for both the replies. I did use the suggested code but still not working.

I have used the same file as I have locally but only changed the ereg to preg statement. Local works fine, remote does not.

No error file about connecting to the database and the home page loads fine so this is an error on validation. As soon as I log in the system takes me to the error in logging in page (locally it takes me to the logged in homepage).

The total code for this section of the validation is as below. I am assuming further deprecation and any help given will be gratefully received:

Code: Select all

// Validate text only
		function validateTextOnly($theinput,$description = '')
			{
			$result = ereg ("^[A-Za-z0-9\ ]+$", $theinput );  // This is deprecated. New preg_match statement used here on remote page
			if ($result)
				{
				return true;
				}
			else
				{
				$this->errors[] = $description;
				return false; 
				}
			}

Re: EREG to PREG_MATCH Error

Posted: Mon Jun 14, 2010 9:22 am
by AbraCadaver
Do this on both local and remote:

Code: Select all

echo get_magic_quotes_gpc();

Re: EREG to PREG_MATCH Error

Posted: Mon Jun 14, 2010 9:43 am
by gazzieh
AbraCadaver wrote:Do this on both local and remote:

Code: Select all

echo get_magic_quotes_gpc();
Okay, and got 11 on both occasions (which is what I would expect, since I run the validation twice).

Therefore, magic quotes are on in both cases.

Re: EREG to PREG_MATCH Error

Posted: Mon Jun 14, 2010 3:43 pm
by gazzieh
The fault lay in the fact that the SQL security system has changed. The new SQL PASSWORD() function checks a 41 character code yet the older style was only 20 characters long. Therefore my system was not able to confirm the password since the stored values were truncated. DOH!

All solved now.