[PHP] Re: How can I get a random number

2001-01-16 Thread Angela

I see that you got a lot of responses, but I didn't see anyone using
what I use.  I had problems using rand() because it wasn't quite random
enough.  The following code is as random as you can get (at least from
what I've seen).

mt_srand ((double) microtime() * 100);
$myrandomnumber = mt_rand($min_number, $max_number);




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: recommended PHP/MySQL host

2001-02-15 Thread Angela

Our company, IBC,  hosts websites.  We currently have PHP4 and MySQL 3.23 on all our
servers.  I would suggest contacting Charone at [EMAIL PROTECTED] or call us at
(937)277-2000.  The prices on our website aren't very accurate.  Often our prices are 
much
cheaper than what you will find there.  Actually, you could more than likely get your 
own
server through us for less than $100 dollars a month.  If you would rather email me 
back,
I can forward the information on to her and find out a price range for what you want.  
If
you have any questions, let me know.
-Angela

-- 
Angela Curtis
Innovative Business Consultants
http://www.ibc2001.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: PHP and cookies and/or headers

2001-02-16 Thread Angela

On your splash page, instead of having it send the user directly to either the english 
or
french site, first have it send to another page on that domain along with a variable to
tell it whether it's english or french.  For example, the English button would be 
linked
to "setcookie.php?Language=English" and the French button would be linked to
"setcookie.php?Language=Francais".  On the setcookie.php page, use an if statement to
determine which language they chose, then inside of it set the cookie then redirect 
them
to the language site of their choice.  For example:

http://www.english.com");
}else{
setcookie("Language", "$Language");
header("location: http://www.francais.com");
}
?>

Then on your home page, you would have it check for these cookies:

http://www.english.com");
}elseif($Language=="Francais"){
header("location: http://www.francais.com");
}else{
show_the_choice_page();
}
?>

I think this would be the best solution.  Let me know if anybody comes up with anything
better.
-Angela

-- 
Angela Curtis
Internet Programmer
Innovative Business Consultants
http://www.ibc2001.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: PHP and cookies and/or headers

2001-02-16 Thread Angela

After reading through the setcookie page on php.net, I found out that for some reason 
it
won't let you redirect to a different site after setting the cookie.  So, as a fix, 
change
the headers on the setcookie.php page to redirect to the index page, and let the index
page take care of the redirecting.
-Angela

 Original Message 
Subject: Re: PHP and cookies and/or headers
Date: Fri, 16 Feb 2001 08:57:23 -0500
From: Angela <[EMAIL PROTECTED]>
To: Jeremy Gillies <[EMAIL PROTECTED]>,[EMAIL PROTECTED]

On your splash page, instead of having it send the user directly to either the english 
or
french site, first have it send to another page on that domain along with a variable to
tell it whether it's english or french.  For example, the English button would be 
linked
to "setcookie.php?Language=English" and the French button would be linked to
"setcookie.php?Language=Francais".  On the setcookie.php page, use an if statement to
determine which language they chose, then inside of it set the cookie then redirect 
them
to the language site of their choice.  For example:

http://www.english.com");
}else{
setcookie("Language", "$Language");
header("location: http://www.francais.com");
}
?>

Then on your home page, you would have it check for these cookies:

http://www.english.com");
}elseif($Language=="Francais"){
header("location: http://www.francais.com");
}else{
show_the_choice_page();
}
?>

I think this would be the best solution.  Let me know if anybody comes up with anything
better.
-Angela

-- 
Angela Curtis
Internet Programmer
Innovative Business Consultants
http://www.ibc2001.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: PHP and cookies and/or headers

2001-02-16 Thread Angela

When they click on the tab to change languages, you could have that go back to a page 
on
the main site, reset the cookie, and then send it on to the site you want it to go to.
-Angela

Jeremy Gillies wrote:
> 
> angela,
> 
> this would work if people did not switch back and forth between langauges.
> We have many bilingual users who want print copies, for example, in french
> and english. Each time they click a little tab at the top, it will switch
> languages and sites too, BUT will remain with the corresponding text in the
> other language.
> 
> thank you for your help so far,
> jeremy
> 
> > -Original Message-
> > From: Angela [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, February 16, 2001 8:57 AM
> > To: Jeremy Gillies; [EMAIL PROTECTED]
> > Subject: Re: PHP and cookies and/or headers
> >
> >
> > On your splash page, instead of having it send the user
> > directly to either the english or
> > french site, first have it send to another page on that
> > domain along with a variable to
> > tell it whether it's english or french.  For example, the
> > English button would be linked
> > to "setcookie.php?Language=English" and the French button
> > would be linked to
> > "setcookie.php?Language=Francais".  On the setcookie.php
> > page, use an if statement to
> > determine which language they chose, then inside of it set
> > the cookie then redirect them
> > to the language site of their choice.  For example:
> >
> >  > if($Language=="English"){
> >   setcookie("Language", "$Language");
> >   header("location: http://www.english.com");
> > }else{
> >   setcookie("Language", "$Language");
> >   header("location: http://www.francais.com");
> > }
> > ?>
> >
> > Then on your home page, you would have it check for these cookies:
> >
> >  > if($Language=="English"){
> >   header("location: http://www.english.com");
> > }elseif($Language=="Francais"){
> >   header("location: http://www.francais.com");
> > }else{
> >   show_the_choice_page();
> > }
> > ?>
> >
> > I think this would be the best solution.  Let me know if
> > anybody comes up with anything
> > better.
> > -Angela
> >
> > --
> > Angela Curtis
> > Internet Programmer
> > Innovative Business Consultants
> > http://www.ibc2001.com
> >

-- 
Angela Curtis
Internet Programmer
Innovative Business Consultants
http://www.ibc2001.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Complex MySQL query for lowest price

2013-01-31 Thread Angela Barone
Hello,

I have a formula that says, if 'specialprice' is not empty and it is 
lower than 'unitprice', use 'specialprice', otherwise use 'unitprice':

Your Price: $%s', 
number_format(mysql_result($result,0,"used_price"),2)); ?>

What I'd like is to add a starting and ending date and if today's date 
is between those dates, then do the above formula, otherwise if today's date is 
not between those dates, then just use 'unitprice'.

This is starting to get too complex for me, so I need some help. ;)  
Hopefully this makes sense.  If I need to be clearer, please let me know.

Thanks!
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Complex MySQL query for lowest price

2013-02-01 Thread Angela Barone
Thank you for everyone's input.  Someone suggested the MySQL list, so I 
posted my question there and got the answer I needed.

Regards,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Not counting my own page visits

2013-03-04 Thread Angela Barone
Hello,

I have a script that counts hits to all the pages in my site and emails 
me a report nightly.  However, it also counts my visits to my site, and when 
I'm coding, I'm hitting a lot of my pages, repeatedly.  I'd like to find a way 
to not count my page visits.

At first, I thought about adding a parameter to each URL and parsing 
that in the script, but that would get old real fast, and also, I may forget to 
add it each time.  Is there a way to tell the script to ignore my visits?

Thank you,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Not counting my own page visits

2013-03-04 Thread Angela Barone
On Mar 4, 2013, at 9:52 AM, Tommy Pham wrote:
> What about ignoring $_SERVER['REMOTE_ADDR'] or $_SERVER['REMOTE_HOST']
> where that matches your public IP or FQDN?

Hi Tommy,

I am checking for $_SERVER['REMOTE_ADDR'] but how would I check that 
against mine?  I don't have a static IP.

Thanks,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Not counting my own page visits

2013-03-04 Thread Angela Barone
On Mar 4, 2013, at 9:56 AM, Ashley Sheridan wrote:
> set a cookie with a long life and check for that, discounting visits when 
> either are true

Hi Ash,

I don't know anything about cookies.  It sounds complicated to me.  Is 
there a simple way to set one?

Thanks,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Not counting my own page visits

2013-03-04 Thread Angela Barone
On Mar 4, 2013, at 11:33 AM, Ashley Sheridan wrote:
> You can manually write a cookie on your machine, or use a special script that 
> only you visit that contains a setcookie() call (it only need be set once). 
> From there on, you can check the $_COOKIES super global for the presence of 
> your cookie.

I don't know why, but I can't get cookies to work.  Here's a script I'm 
calling from my browser:







Test Page


"; ?>
"; ?>



The domain is being displayed but the cookie is not.  There's no cookie 
in the browser prefs, either.  What am I doing wrong?

Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Not counting my own page visits

2013-03-05 Thread Angela Barone
On Mar 4, 2013, at 3:49 PM, David Robley wrote:
> Misunderstanding what $cookie contains? It is a boolean, i.e. it will be 
> true or false depending on whether the cookie was set or not. To echo the 
> contents of a cookie, you need to use the cookie name, viz
> 
> "; ?>

You're right - I didn't really understand cookies.  However, with 
everyone's help here, and by searching the web, I got it to work.  

Thank you to Tommy, Ash, and David!
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
I'm looking for an 'unless' statement, but as far as I can tell, PHP 
doesn't have one.  Hopefully someone can help me rewrite my statement.

In English, I want to say: "always do something UNLESS these 3 
conditions are met".

The best I've been able to come up with in PHP is this:

if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and 
($current_dt < ($saved_dt + 3600)) ) {
return;
} else {
$query  = "UPDATE `table` SET `hits` = '$count', `agent` = '$agent', 
`ts` = '$date_time'  WHERE `page` = '$page'";
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());
}

However, I've read where this is not really acceptable.  Can someone 
help me eliminate the 'else' portion of this if statement?

Thank you,
Angela

P.S.  I realize the above isn't complete code but it should still be clear.  If 
not, let me know.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
On Mar 11, 2013, at 2:38 PM, Jonathan Sundquist wrote:

> Since you already have the return statement with the if statement the else 
> isn't required. If those three statements are true you would exit the call 
> any ways

I don't follow.  The else contains the meat of the statement. 

Angela

Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
On Mar 11, 2013, at 3:47 PM, Ashley Sheridan wrote:
> if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and 
> ($current_dt < ($saved_dt + 3600)) ) )

Hello Ash,

This makes sense to me, but I can't get it to work, so I'm either not 
understanding it or I'm asking the wrong question.  Here's a complete scriptlet:



Using the supplied data, the result should be "Don't save."  Can you 
see what's wrong?

Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote:
> the variable $current_page does not exist. 

That was my problem. :(  I've been staring at this for too long.  Too 
bad there's not a 'use strict' pragma.

> I would also suggest keeping with your original statement to return early and 
> return often. Its best to exit out of your functions sooner than later.  
> Specially if its a large function.

O.K.  I just thought there might be a more elegant way of doing it.  I 
at least got rid of the else statement like you mentioned.

Thanks for your help,
Angela

[PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
I've been getting the following error for awhile now, but I can't 
figure out why it's happening:

Invalid argument supplied for foreach() in ... sample.php on line 377

Here's that portion of code:

include("states_zipcodes.php");

// Check if Zip Code matches from states_zipcodes
$zip_short = substr($zip, 0, 3);
foreach ($states[$state] as &$zip_prefix) {   // <-- line 377
if ($zip_prefix == $zip_short) {
break;
} else {
$match = 'no';
}
}

It doesn't happen all the time, so I'm thinking that some spambot is 
populating the HTML form with something the script doesn't like(?).  However, I 
tested that myself by entering text, or by entering just 2 digits, but there 
was no error.  FYI, I do have code in the script that catches faulty input and 
warns people in their browser to go back and re-enter the correct data, so I'm 
at a loss as to why this is happening.

How can I see what's triggering this to happen?  I have the following 
line in my php.ini:

error_reporting = E_ALL & E_STRICT & E_NOTICE & E_DEPRECATED

Thank you,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
On Mar 12, 2013, at 2:26 PM, Marco Behnke wrote:

> what is in $states?
> Looks like $states[$state] is not an array.

Here's a sample:

 array( '350','351','352','353', ),
'AK' => array( '995','996','997','998','999', ),
'AZ' => array( '850','851','852','853','854', ),
...
'WI' => array( '530','531','532', ), 
'WY' => array( '820','821','822','823','824', ),
);
?>


> side effects if you don't act carefully with it.

I don't remember where that came from, but for the most part, this 
script works perfectly.  However, I removed it and will test without it.

Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
I think I figured it out.

 array( '350','351','352','353', ),
'AK' => array( '995','996','997','998','999', ),
'AZ' => array( '850','851','852','853','854', ),
'WI' => array( '530','531','532', ), 
'WY' => array( '820','821','822','823','824', ),
);

$zip = 35261;
$state = 'XX';

$zip_short = substr($zip, 0, 3);
foreach ($states[$state] as $zip_prefix) { 
if ($zip_prefix == $zip_short) {
echo "State = $state";
} else {
echo 'no';
}
}
?>

Running this script, I got the same error as before.  If $state is a 
known state abbreviation in the array, everything is fine, but if someone was 
to enter, say 'XX' like I did above or leave it blank, then the error is 
produced.  I placed an if statement around the foreach loop to test for that 
and I'll keep an eye on it.

Thank you for getting me to look at the array again, which led me to 
look at the State.

Angela

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
On Mar 12, 2013, at 5:16 PM, David Robley wrote:
> Presumably there is a fixed list of State - those are US states? -

> so why not provide a drop down list of the possible choices?

There is, but the problem must have been that if someone didn't select 
a State, $state was blank.  I've since given the "Select a State..." choice a 
value of 'XX' and I'm now looking for that in the if statement I mentioned 
before.

Angela

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 9:07 AM, Jim Giner wrote:
> Why not just check if the $state exists as a key of the array $states before 
> doing this?

Jim,

Are you thinking about the in_array function?

Angela

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 4:24 PM, Matijn Woudt wrote:
> That wouldn't work, in_array checks the values, and your states are in the 
> keys. Use:
> if(isset($states[$state])) 

Hi Matijn,

Before I received your email, I ran across if(array_key_exists) and it 
seems to work.  How does that differ from if(isset($states[$state]))?

Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 5:02 PM, David Harkness wrote:
> isset() will return false for an array key 'foo' mapped to a null value 
> whereas array_key_exists() will return true. The latter asks "Is this key in 
> the array?" whereas isset() adds "and is its value not null?" While isset() 
> is every-so-slightly faster, this should not be a concern. Use whichever 
> makes sense for the context here.

Hi David,

Thank you for the explanation.  It's nice to know the difference 
between them.  Since they are equivalent for my use, I went with 
array_key_exists, simply because it makes more sense to me in English. ;)

Thanks again to everyone.  I got it to work _and_ there are no more 
errors!!!

Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Detecting massive web hits

2013-04-12 Thread Angela Barone
Does anyone know if there's a ready-made script that detects if someone 
hits multiple web pages within seconds of each other and then can temporarily 
ban them by IP from accessing our site?

Looking through the logs, I see someone/something hit each and every 
page of a site I work on within only a few seconds of each other.  I seriously 
doubt they are a customer. ;)

I'd appreciate any insights.

Thank you,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Looking for complete entered URL

2013-04-20 Thread Angela Barone
I've written a script that logs all visits to a web site, complete with 
referrer and IP address.  It also logs all 4xx errors.  What I'd like to add to 
this is, if someone adds extra code after the page_name.php, to be able to 
capture any extra code and log that.

I've tried:

$_SERVER['QUERY_STRING']
$_SERVER['REDIRECT_QUERY_STRING']
$_SERVER['REDIRECT_URL']

but nothing seems to get logged.

Is there a way, when either a false url is entered and a 404 is 
generated, or just when someone tacks on extra code to the URL, that I can grab 
that extra info?  I'm looking for the complete URL that was entered by the 
user, not anything returned by the server.

I've created my own 4xx_error.php files which calls my tracking script, 
along with creating the proper ErrorDocument lines in the main .htaccess file.

There are a lot of pages that have come up in my search, but nothing 
seems to pertain to what I'm trying to do.

Thank you,
Angela

BTW, I know about Piwik and I use that, as well.  This is something I'm doing 
on my own.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] random html +(hi)

2004-01-16 Thread Angela K Hilton
Hi All

I'm new to this list and I suppose fairly new to PHP - and hope that
this question is in keeping with the type of thing that's usually asked.

I'm trying to dynamically randomise a chunk of HTML that is used on a
page, aka  random image, so that each time a client opens the page [or
refreshes] a part of the page changes.  

The chunks of HTML are saved in their own directory as .htm files.  I
was hoping to adapt the following code I have managed to cobble together
to display random images:

";

?>

I'd like the code to take the HTML and place it in a ,
probably using a  (I think I'm OK with this once
the code is sorted).  

However - I don't seem to be able to progress any further with this -
I'm sure I'm missing something very basic - but I just can't get past
this point.

I'd be grateful for any pointers with this.

TIA
ange

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] mt_strand

2004-02-13 Thread Angela K Hilton
Hi All
 
I could do with some pointers in using mt_strand.
 
I understand that because my server has 

 
 and have found the following in the PHP manual:
 

 
However - I'm not 100% sure how to incorporate it into my code - I have
tried a few things but each time I break the code.
 
Any help will be appreciated.
 
Thanks
Ange
***
Angela K Hilton
Web & E-Learning Officer
ISD, UMIST
Tel: 0161 306 3109
***
 


RE: [PHP] mt_strand

2004-02-13 Thread Angela K Hilton
Hamid



works fine - all the code works OK - apart from the seed issue.

A

***
Angela K Hilton
Web & E-Learning Officer
ISD, UMIST
Tel: 0161 306 3109
***


-Original Message-
From: Hamid Hossain [mailto:[EMAIL PROTECTED] 
Sent: 13 February 2004 10:45
To: [EMAIL PROTECTED]
Subject: RE: [PHP] mt_strand

Hi Angela,

I don't understand why you are using the following line:


You have to use somthing like:


The other part of your code looks fine to me.

Regards,
Hamid

---
Check Amazon.com's Latest PHP books:
http://www.amazon.com/exec/obidos/redirect?tag=zawraqclassif-20&path=tg/
browse/-/295223

Start Accepting CreditCard at your site in minutes:
http://www.2checkout.com/cgi-bin/aff.2c?affid=106720

Download Alexa Tool Bar to stop Pop-ups for FREE:
http://download.alexa.com/?amzn_id=zawraqclassif-20

Download Ready-Made Templates for your site:
http://www.aplustemplates.com/cgi/affiliates/c1.cgi/zawraq_ad
---

Original Message Follows
From: "Angela K Hilton" <[EMAIL PROTECTED]>
To: "PHP-General" <[EMAIL PROTECTED]>
Subject: [PHP] mt_strand
Date: Fri, 13 Feb 2004 10:37:47 -

Hi All

I could do with some pointers in using mt_strand.

I understand that because my server has 


  and have found the following in the PHP manual:



However - I'm not 100% sure how to incorporate it into my code - I have
tried a few things but each time I break the code.

Any help will be appreciated.

Thanks
Ange
***
Angela K Hilton
Web & E-Learning Officer
ISD, UMIST
Tel: 0161 306 3109
***

_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] UK Postcodes Format

2004-02-17 Thread Angela K Hilton
I 'Think' there are also different formats for military bases here and
overseas.

[this is a faint memory from validating post codes in a database some
years ago]

A

*******
Angela K Hilton
Web & E-Learning Officer
ISD, UMIST
Tel: 0161 306 3109
***


-Original Message-
From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] 
Sent: 17 February 2004 12:15
To: 'Roddie Grant'; Shaun; [EMAIL PROTECTED]
Subject: RE: [PHP] UK Postcodes Format

On 17 February 2004 10:43, Roddie Grant wrote:

> on 17/2/04 10:25 am, Shaun at [EMAIL PROTECTED] wrote:
> 
> > Hi,
> > 
> > does anyone know the format of the postcodes in the UK so I can
> > keep my database accurate? 
> > 
> > Thanks
> 
> 
> Try http://javascript.internet.com/forms/uk-postcode-validation.html

Wow, at a glance I'd say that looks like pretty crappy JavaScript, and
also not a totally accurate UK postcode checker.

The only guaranteed way to fully validate a UK postcode is to purchase
the Royal Mail's Postcode Address File (PAF) (and subscribe to its
updates!), but you can validate the format fairly closely with some
simple rules.

For example, here's a regexp that matches valid UK postcode patterns:

   /[A-Z]{1,2}[0-9][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{1,2}/

or, in English:

* an "outward" code consisting of:
  - 1 or 2 alphabetic characters
  - followed by 1 or 2 digits, or 1 digit and 1 letter

* a space

* in "inward" code consisting of:
  - 1 digit
  - followed by 2 letters, but not including C, I, K, M, O or V.

(The special code GIR 0AA also exists for the headquarters of the
formerly-Government-owned Girobank, now part of the Alliance &
Leicester, and is the only one that doesn't match these rules).

Although this will check for potentially valid formats, there are a
number of other checks you can make if you wish:

- the initial 1 or 2 letters come from a restricted set of about 120,
indicating the main sorting office which handles mail for an area --
generally they correspond to a large town or city (B - Birmingham, L -
Liverpool, LS - Leeds, etc.) but London ones are taken from the much
older London postal district names (E - East, EC - East Central, etc.)
and a few represent more general area names (ZE - Shetland Islands, for
example.  (I could probably produce a list of these fairly easily.)

- The range of values in the rest of the "outward" code is likewise
restricted; the range is different for each area, with many restricted
to 20 or less, and none uses the full set of 1-99; however, higher
values are often used for special purposes (98 and 99 for PO Boxes, for
example), and most of the larger areas have multiple disjoint ranges.

- The only postcodes which have a final letter in the "outward" portion
of the code are some of the London districts (off the top of my head,
EC, SW, W and WC only, I think, and maybe not all of those!).

- For each "outward" code, there may also be restrictions on the range
of "inward" codes, and these will again be different for each area (for
example, for my home outward code all inward codes begin with a 2; in
the neighbouring outward code, all inward codes begin with a 3).  These
are so numerous and diverse that they're not really worth bothering
about unless you're going the full-blown PAF route.

Anyway, this is probably already far more information than you were
expecting, so I'll shut up now!

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php