RE: [PHP] bulk mail()

2002-06-14 Thread Jeff Field

I've been doing the following sending personalized mail to 600+ recipients,
so far without any signs of discomfort anywhere:

set_time_limit($total_rows * 1);  // up the script timeout 1 second per
email

BTW, I use qmail; not sendmail.  As I've never used sendmail, I don't know
if this is part of your problem or not.  I'm guessing a bit, but based on
600+ emails, I'd say that the script itself takes about 10-15 seconds; the
mail to be delivered takes a bit longer, perhaps another minute or two.

Jeff

 -Original Message-
 From: Justin French [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 12, 2002 6:45 AM
 To: php
 Subject: [PHP] bulk mail()


 Hi all,

 I've got a mailing on a website, with email address' / names / etc in a
 MySQL table.

 I think there's around 120 on it at the moment.

 I've been noticing a growing lag on the sending of mail though...
 I've got a
 script which takes a message from a form, then runs a while loop
 through the
 rows of the mailing_list table, replacing a special string with the
 subscribers name, and sending using the mail() command.

 However, this time, the script actually failed, with a failure when
 attempting to access blah.com/foo.php (the sending script).  I
 have no idea
 if SOME people got the email, or what, and have no idea how to check.

 So, I make the assumption that as the mailing list has grown, the script
 time has slowed... now it's too big (or the server was too busy)
 to process
 all the emails before the script timed out.


 If I didn't want to personalise the emails, I'm sure the script
 would run a
 lot quicker with every address in the Bcc header, but since we personalise
 each email, I can't see any option other than using mail() 200
 times...  and
 it's only going to get a lot worse as we climb to 1000+.

 So, what options do I have?

 Break the mailing list up into batches of 40 or so?  How would I implement
 something like this?


 Any advice / concepts / ideas welcome!


 Justin French
 
 Creative Director
 http://Indent.com.au
 


 --
 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




[PHP] possible to add a record number to a query?

2002-06-13 Thread Jeff Field

I would like to have a column returned in a query that tells you which
record I'm looking at?  Sort of like an auto_increment?  IOW, the query
results would look like:

record   first   last

  1  johndoe
  2  joe blow
  3  carol   fisher

The table only has first and last, but I want the results to add something
like record to tell me which record it is.  Thanks for any help!

Jeff

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





RE: [PHP] possible to add a record number to a query?

2002-06-13 Thread Jeff Field

Yes, there is a particular reason.  The actual query I do pulls information
from two tables and has both ORDER BY and GROUP BY clauses.  The
auto_increment column (think of the query results as a table) will give me
the rank of the results.  I know how to manipulate the data in PHP to
accomplish what I need.  I just thought there might be a way in which the
query could do it up front.  Sort of like when you want to know how many
times a particular record exists, you can do a COUNT(*).  I just want the
results to basically give me a column in the query that lists the results 1,
2, 3, etc.  Make sense?

Thanks for your help!

Jeff

 -Original Message-
 From: Jason Wong [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, June 13, 2002 8:30 AM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] possible to add a record number to a query?


 On Thursday 13 June 2002 20:27, Jeff Field wrote:
  I would like to have a column returned in a query that tells you which
  record I'm looking at?  Sort of like an auto_increment?  IOW, the query
  results would look like:
 
  record   first   last
 
1  johndoe
2  joe blow
3  carol   fisher
 
  The table only has first and last, but I want the results to
 add something
  like record to tell me which record it is.  Thanks for any help!

 Is there any reason why you need/want to do this? Data are stored
 in a db in
 no particular order. If you want a particular order add an ORDER
 BY clause.
 If you want 'row' numbers then just fudge it in php -- assign a
 row number to
 each record you retrieve from the query.

 --
 Jason Wong - Gremlins Associates - www.gremlins.com.hk
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *

 /*
 There's such a thing as too much point on a pencil.
   -- H. Allen Smith, Let the Crabgrass Grow
 */


 --
 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




RE: [PHP] possible to add a record number to a query?

2002-06-13 Thread Jeff Field

1) Yes, I'm using MySQL
2) You're right. This is not a PHP question.  My apologies to the list!

Thanks for the feedback!  I'll give it a try (and the other one in the other
email).

Jeff

 -Original Message-
 From: John Holmes [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, June 13, 2002 11:44 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: RE: [PHP] possible to add a record number to a query?


 You can do it with two queries.

 SELECT @a:=0;

 SELECT @a:=@a+1, * FROM table;

 This would be better taken to a MySQL list, though. Actually, you never
 said what DB you were using. This works in MySQL.

 ---John Holmes...

  -Original Message-
  From: Jeff Field [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, June 13, 2002 10:01 AM
  To: [EMAIL PROTECTED]
  Subject: RE: [PHP] possible to add a record number to a query?
 
  Yes, there is a particular reason.  The actual query I do pulls
  information
  from two tables and has both ORDER BY and GROUP BY clauses.  The
  auto_increment column (think of the query results as a table) will
 give
  me
  the rank of the results.  I know how to manipulate the data in PHP
 to
  accomplish what I need.  I just thought there might be a way in which
 the
  query could do it up front.  Sort of like when you want to know how
 many
  times a particular record exists, you can do a COUNT(*).  I just want
 the
  results to basically give me a column in the query that lists the
 results
  1,
  2, 3, etc.  Make sense?
 
  Thanks for your help!
 
  Jeff
 
   -Original Message-
   From: Jason Wong [mailto:[EMAIL PROTECTED]]
   Sent: Thursday, June 13, 2002 8:30 AM
   To: [EMAIL PROTECTED]
   Subject: Re: [PHP] possible to add a record number to a query?
  
  
   On Thursday 13 June 2002 20:27, Jeff Field wrote:
I would like to have a column returned in a query that tells you
 which
record I'm looking at?  Sort of like an auto_increment?  IOW, the
  query
results would look like:
   
record   first   last
   
  1  johndoe
  2  joe blow
  3  carol   fisher
   
The table only has first and last, but I want the results to
   add something
like record to tell me which record it is.  Thanks for any help!
  
   Is there any reason why you need/want to do this? Data are stored
   in a db in
   no particular order. If you want a particular order add an ORDER
   BY clause.
   If you want 'row' numbers then just fudge it in php -- assign a
   row number to
   each record you retrieve from the query.
  
   --
   Jason Wong - Gremlins Associates - www.gremlins.com.hk
   Open Source Software Systems Integrators
   * Web Design  Hosting * Internet  Intranet Applications
 Development *
  
   /*
   There's such a thing as too much point on a pencil.
 -- H. Allen Smith, Let the Crabgrass Grow
   */
  
  
   --
   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


 --
 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




[PHP] Access control question

2002-06-07 Thread Jeff Field

Quick question...

I have a site where user's log in, they put their user name and password in
a form and if they are verified against the database, session variables are
created,

$_SESSION['user'];
$_SESSION['pass'];

and they get sent to the next page by way of,

header(Location: https://www.mysite.com/login/;);  // not a real site

On that page, and all other pages for which I want to control access, I then
put a little access control script (actually, an include file) at the top of
each page that checks to see that $_SESSION['user'] is present.  If
$_SESSION['user'] is *not* present, I send them back to the login page.  If
$_SESSION['user'] *is* present, they're granted access to the page.

Here's the question:

Is it simply enough to just check that $_SESSION['user'] is present, and
therefore, by that alone assume the user has logged in and should be granted
access?  Or, should I be verifying the $_SESSION['user'] and
$_SESSION['pass'] against the database on every page?

The reason I ask is that an article (tutorial) on access control runs a
script that hits the database every page.  But, to me, that seems like a
waste because simply having the $_SESSION['user'] present means they've
already logged in.  Am I missing something here?

Thanks, as always!

Jeff


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




RE: [PHP] Access control question - follow-up question

2002-06-07 Thread Jeff Field

Your way to check for privileges sounds good.  However, at my site, for this
one area (basically, the customer's area) there's only one privilege; you
either have access or you don't.  So, I'm assuming my way is probably good
enough for now.

In regards to the presence of the session itself being good enough for
verification, the reason I would check for the $_SESSION['user'] is that
that variable means they are logged in, as opposed to merely having a
session in use.  I say that because, given that I may want to start a
session for other uses, such as tracking a user's navigation through the
website, then the presence of the session itself would not be good enough to
know if they've logged in or not.

In regards to Passing/testing the password on each page is unnecessary and
poses security risks., I'm under the impression that when I create the user
and password variables, the variables are only available in the session
cookie on my own server, not in the cookie that is sent to the user to
maintain sessions.  The cookie sent to the user merely contains the session
ID.  Therefore, other than someone hijacking the session, I'm a little
unclear as to the security risk.  Have I got this right?

Thanks!

Jeff

 -Original Message-
 From: Analysis  Solutions [mailto:[EMAIL PROTECTED]]
 Sent: Friday, June 07, 2002 10:42 AM
 To: PHP List
 Subject: Re: [PHP] Access control question


 Hi Jeff:

 On Fri, Jun 07, 2002 at 10:25:27AM -0500, Jeff Field wrote:
 
  Is it simply enough to just check that $_SESSION['user'] is present, and
  therefore, by that alone assume the user has logged in and
 should be granted
  access?  Or, should I be verifying the $_SESSION['user'] and
  $_SESSION['pass'] against the database on every page?

 If you validate the user/pass before starting a session for the person,
 then the existence of the session itself proves the person has logged
 in.  No?  Passing/testing the password on each page is unnecessary and
 poses security risks.

 Disclaimer:  I don't use PHP's session functions for sessions.

 What I do in my system is give everyone a session.  All folks who
 haven't logged in are one user.  Once they log in, my session database
 associates their UserID with their session.  The UserID isn't checked on
 each page.  When access to a particular page needs to be limited, I
 check their permission level (which is in another field of the session
 database) to ensure they have the privileges needed to perform the
 operation.

 Enjoy,

 --Dan

 --
PHP classes that make web design easier
 SQL Solution  |   Layout Solution   |  Form Solution
 sqlsolution.info  | layoutsolution.info |  formsolution.info
  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

 --
 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




RE: [PHP] Access control question - follow-up question

2002-06-07 Thread Jeff Field

Absolutely right!  I'm storing the password needlessly.  I've got the user
name and that's all I need for anything further.  Thanks!

Jeff

 -Original Message-
 From: Analysis  Solutions [mailto:[EMAIL PROTECTED]]
 Sent: Friday, June 07, 2002 12:42 PM
 To: PHP List
 Subject: Re: [PHP] Access control question - follow-up question


 On Fri, Jun 07, 2002 at 11:32:48AM -0500, Jeff Field wrote:
 
  In regards to Passing/testing the password on each page is
 unnecessary and
  poses security risks., I'm under the impression that when I
 create the user
  and password variables, the variables are only available in the session
  cookie on my own server, not in the cookie that is sent to the user to
  maintain sessions.  The cookie sent to the user merely contains
 the session
  ID.  Therefore, other than someone hijacking the session, I'm a little
  unclear as to the security risk.  Have I got this right?

 A general rule:  if something doesn't need to be stored, don't store it.
 This saves time and space.

 In the instance of passwords, storing them needlessly keeps sensitive
 information around.  This poses a problem in the event your system gets
 compromised.  There are lots of ways that can happen, both known and yet
 to be discovered and yet to be created.  So, it's just safer not to do
 it.

 --Dan

 --
PHP classes that make web design easier
 SQL Solution  |   Layout Solution   |  Form Solution
 sqlsolution.info  | layoutsolution.info |  formsolution.info
  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

 --
 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




RE: [PHP] Sessions question (-enable-trans-sid)

2002-06-06 Thread Jeff Field

Thanks to all for their help on this.  As a follow-up, and after a bunch of
playing around with this yesterday, here's what I've come to learn.  Perhaps
it will be helpful to others:

With enable-trans-id compiled into PHP and the following directives in
php.ini:

session.use_cookies = 0(PHP uses cookies for sessions - off)
session.use_trans_sid = 1  (PHP uses enable-trans-id for sessions - on)

PHP will automatically append the SID to the end of relative links 100% of
the time and will not use cookies no matter whether the user has cookies
enabled for their browser or not.

In the following case (and I presume the more normal way of doing things):

session.use_cookies = 1(PHP uses cookies for sessions - on)
session.use_trans_sid = 1  (PHP uses enable-trans-id for sessions - on)

PHP will behave the same way for those users that do *not* have cookies
enabled for their browser as in the first example, i.e. append links 100% of
the time.  However, for those users that have cookies enabled for their
browser, PHP will append the SID to the links only on the first hit to a
page.  Then, when a user requests the next page, the auto-rewriting of the
URI's stops and cookies are used from that point forward.

Actually, that all makes sense, as the first time a user requests a page,
there's no way for PHP to know if the browser will accept cookies or not.
But, on the second request, the browser will send the cookie back to PHP
(along with the appended URI), and PHP from that point on knows that the
browser accepts cookies and PHP will then drop the rewriting of the URI's.

I hope I've got this all correct.  The one observation I'd make in regards
to using cookies vs. URI's to maintain the session is this (and please
someone correct me if I'm wrong):

If a user does *not* have cookies enabled for their browser, you can lose
the session if the user hits an html page at your site (because PHP will not
be involved and will not rewrite the URI's for the .html page).  Not good.

If a user *does* have cookies enabled, they can hit non-PHP pages all they
want and when they get back to a PHP page, the session is still intact.

So, it would seem, while the SID being appended to all URI's should work for
all users, non-PHP pages will break the session (not good).  And, as for the
cookie method, not all users have cookies enabled for their browser (also,
not good).  Therefore, IMO, neither the cookie method or appending the URI
method will work as you'd like 100% of the time.

I suppose one thing you could do so that non-PHP pages won't break the
session for those users that don't have cookies enabled would be to just run
every page in your site through PHP.  That way, the URI's for every page
will be appended with the SID, and maybe that's the way to go.

Anyway, I hope I've got this all right and I hope it helps someone.

Jeff


 -Original Message-
 From: Jeff Field [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 05, 2002 11:56 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Sessions question (-enable-trans-sid)


 Hi,

 I'm confused about one thing regarding sessions and haven't been able to
 find the definitive answer anywhere.  Hopefully, I can here.

 There are two ways to enable sessions:

 1) Session ID is passed through cookies
 2) Session ID is passed through the URL, either done manually or by
 automatic URL rewriting

 All the books, tutorials, etc. basically say that cookies are the
 way to go
 but when users don't have cookies enabled, you have to use the
 URL method.
 Since I have an e-commerce site that is available to the world,
 I'm assuming
 *some* are not going to have cookies enabled.  Duh!

 So, from what I've read, you can implement the URL method of sessions by
 either manually attaching the session ID to the URLs, or, by compiling PHP
 with enable-trans-sid, which will add the session ID to the URL's
 automatically.  The answer that I haven't been able to find is this:

 Is this a one or the other proposition?  IOW, if I implement sessions with
 cookies, then I can't use the URL method?  Or, if I implement the
 URL method
 (with enable-trans-sid), I can't use the cookie method?  Or, do
 they work in
 combination.  IOW, does PHP automatically know that if a user has cookies
 enabled, PHP will use the cookie method and, when cookies are
 *not* enabled,
 PHP automatically implements the URL method?

 Thanks for the help!

 Jeff


 --
 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




[PHP] Weird intermittent No Database Selected problem

2002-06-06 Thread Jeff Field

I apologize...I just posted this to the database list but then realized it
may not be a database issue, so thought I'd better give it a shot over here.

Help!

I've been having a weird problem today (and maybe it's been there all along,
just haven't noticed...it's only been live a few days).  I have a web page
that allows users to query my database by either subject or alphabet (A-Z).
Today (and I think I noticed it once before but didn't pay much attention),
if you do a query, the first time it comes back with the results.  The
second time, clicking the same letter (or sometimes other letters), for
instance, it comes back with a Database Not Selected error.  Or, every
time in a row for a dozen times it comes back with a Database Not Selected
error.  Or, sometimes it comes back with the results just fine for twenty
times in a row. Or, ...

You get the idea.  It doesn't happen all the time, just sometimes, and in no
particular order.  Very strange because I'm not changing a dang thing.
Anyway, I've already tried rebooting the server, no change.  And, I've tried
accessing the web page from other machines, same problem.  Has anyone ever
run into this?

I'm running Red Hat 7.2, Apache 1.3.23, MySQL 3.23.49a, and PHP 4.2.1.

Here's the code in the web page with only some name changes (for security,
ya know):

?php
function Query()
{
global $mydb, $recordset, $total_rows, $letter;
$letter = $_GET['letter'];
mysql_select_db($database_mydb, $mydb);
$query = sprintf(SELECT name
FROM tbl_mytable
WHERE name LIKE %s
ORDER BY name ASC,
SQLStr($letter . %, text));
$recordset = mysql_query($query, $mydb) or die(mysql_error());
$total_rows = mysql_num_rows($recordset);
}
?

And then the code in my include where I keep all the db connection stuff:

?php
$hostname_mydb = localhost;
$database_mydb = mydb;
$username_mydb = user;
$password_mydb = ;
$mydb= mysql_pconnect($hostname_mydb, $username_mydb, $password_mydb) or
die(mysql_error());
?

Any help is appreciated!!  Thanks!

Jeff


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




RE: [PHP] Weird intermittent No Database Selected problem

2002-06-06 Thread Jeff Field

Thanks for the help, all!  Here was the problem...I think, I'm pretty sure,
eh?

In mysql_select_db($database_mydb, $mydb), I have the variable,
$database_mydb, which is actually something that Macromedia's Dreamweaver
MX created (for those that don't know it, Dreamweaver MX supports a little
PHP).

Well, not to put the blame on Macromedia, it was all my fault and I now feel
a bit stupid, I think it all boiled down to $database_mydb not being
declared global in the function I wrote to do the query.

Funny that it worked probably 95% of the time.  Must have been due to
mysql_pconnect or something holding open previous connections to the db and
the script just connecting to the last connected db.  Anyway...

Sorry for the trouble!

Jeff

 -Original Message-
 From: hugh danaher [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, June 06, 2002 5:37 PM
 To: [EMAIL PROTECTED]
 Cc: php
 Subject: Re: [PHP] Weird intermittent No Database Selected problem


 Are all the variables needed for the function getting into your
 call_user_func()?  Also, perhaps some aren't set or are being
 unset outside
 your function--say, you are opening a new page and not passing all the
 variables to it.  The function (which apparently works) isn't getting set
 variables.  Try echoing the input variables just above the
 function call and
 see if they're all there.
 Hope this helps,
 Hugh

 - Original Message -
 From: Jeff Field [EMAIL PROTECTED]
 To: Php-General (E-mail) [EMAIL PROTECTED]
 Sent: Thursday, June 06, 2002 2:34 PM
 Subject: RE: [PHP] Weird intermittent No Database Selected problem


  Hmmm...not sure how to check the status of the db function calls (sorry,
 I'm
  relatively new to PHP, help on this is appreciated), but I did add the
  following to the script:
 
  echo Error  . mysql_errno ( ). :  . mysql_error ( );
 
  It prints out Error 0: when the script runs just fine, but
 nothing when
  the page comes back with No Database Selected.
 
  Any thoughts?  Thanks!
 
  Jeff
 
   -Original Message-
   From: Scott Hurring [mailto:[EMAIL PROTECTED]]
   Sent: Thursday, June 06, 2002 4:15 PM
   To: Php-General (E-mail)
   Subject: RE: [PHP] Weird intermittent No Database Selected problem
  
  
   I assume you're not checking the status returned by the
   database function calls, becuase they'd probably give
   you valueable information on *why* it's doing that.  :)
  
   try checking the return val, and (if using mysql) print
   out mysql_error() if you get a bad return val.
  
   ---
   Scott Hurring
   Systems Programmer
   EAC Corporation
   [EMAIL PROTECTED]
   Voice: 201-462-2149
   Fax: 201-288-1515
  
-Original Message-
From: Jeff Field [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 06, 2002 4:58 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Weird intermittent No Database Selected problem
   
   
I apologize...I just posted this to the database list but
then realized it
may not be a database issue, so thought I'd better give it a
shot over here.
   
Help!
   
I've been having a weird problem today (and maybe it's been
there all along,
just haven't noticed...it's only been live a few days).  I
have a web page
that allows users to query my database by either subject or
alphabet (A-Z).
Today (and I think I noticed it once before but didn't pay
much attention),
if you do a query, the first time it comes back with the
 results.  The
second time, clicking the same letter (or sometimes other
letters), for
instance, it comes back with a Database Not Selected error.
 Or, every
time in a row for a dozen times it comes back with a
Database Not Selected
error.  Or, sometimes it comes back with the results just
fine for twenty
times in a row. Or, ...
   
You get the idea.  It doesn't happen all the time, just
sometimes, and in no
particular order.  Very strange because I'm not changing a
 dang thing.
Anyway, I've already tried rebooting the server, no change.
And, I've tried
accessing the web page from other machines, same problem.
Has anyone ever
run into this?
   
I'm running Red Hat 7.2, Apache 1.3.23, MySQL 3.23.49a, and
 PHP 4.2.1.
   
Here's the code in the web page with only some name changes
(for security,
ya know):
   
?php
function Query()
{
global $mydb, $recordset, $total_rows, $letter;
$letter = $_GET['letter'];
mysql_select_db($database_mydb, $mydb);
$query = sprintf(SELECT name
FROM tbl_mytable
WHERE name LIKE %s
ORDER BY name ASC,
SQLStr($letter . %, text));
$recordset = mysql_query($query, $mydb) or
die(mysql_error());
$total_rows = mysql_num_rows($recordset);
}
?
   
And then the code in my include where I keep all the db
connection stuff:
   
?php
$hostname_mydb = localhost;
$database_mydb = mydb;
$username_mydb = user;
$password_mydb = 

[PHP] regex help

2002-05-26 Thread Jeff Field

This is not really specific to PHP (although the information might be useful
for all that form validation we all do), and for that I apologize in advance
(does anyone know of a regex mailing list?), but maybe someone here can help
with the following:

I find no good regex for checking valid domain names.  None that I have seen
take into account the fact that, although dashes (-) and dots (.) are
allowed in a domain name, the domain name can neither begin with nor end
with a dash or dot, and additionally, two dashes or two dots in a row are
not allowed and a dash followed by a dot or a dot followed by a dash are not
allowed.

So, I've come up with two regex's for checking domain names. The first one
checks that the name contains alphanumerics, the dash and the dot, and
neither begins with or ends with a dash or dot:

   ^[a-z0-9]$|^[a-z0-9]+[a-z0-9.-]*[a-z0-9]+$

The second one checks that two dashes and two dots are not together and that
a dash followed by a dot or a dot followed by a dash are not together:

   --|\.\.|-\.|\.-

Putting it all together, the way I check for a valid domain name is with the
following:

   if (eregi(^[a-z0-9]$|^[a-z0-9]+[a-z0-9.-]*[a-z0-9]+$, $domain_name) !=
true
  OR eregi(--|\.\.|-\.|\.-, $domain_name) == true
   {
  error;
   }

So, my question (finally!) is this:

Is there any way to combine both expressions (basically, one part that
checks for false and one part that checks for true) into one regex that just
returns true or false?  I haven't been able to find any documentation that
shows me how to do that, basically a like this but not like this syntax.

BTW, anticipating someone mentioning the fact that the above regex's don't
check for a domain name ending with a dot followed by three characters max
(as in .com, .net, etc.), it's because that long-held truth is no longer
true.  We now have .info and .museum, and who know what the future will
bring.

About the only truth left is that domain names end in a dot followed by two
characters minimum (there are the country code domains like .us, .de. etc.
but there are no one character TLD's at present and I would expect perhaps
not for a long long time, but you never know).  Perhaps someone would expand
on the regex above to include checking for a name ending with a dot followed
by two characters minimum, I just haven't been into regex's long enough to
know how).

Of course, you could get really anal about all this and check for domain
names that only end in the current ICANN root server TLD's (about 260 or so,
I believe), but that wouldn't account for TLD's that operate within other
root servers (there's always sumthin').  Anyways,

Any help with the above is certainly appreciated!

Jeff


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




[PHP] using array to declare globals in function?

2002-05-24 Thread Jeff Field

Anyone know how to declare globals in a function from an array?  The
following doesn't seem to work:

foreach($_POST as $key = $value)
global $form_var[$key];

Thanks for any help!

Jeff


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




[PHP] matching two form fields function?

2002-05-23 Thread Jeff Field

I feel bad about asking a question like this, but I've spent quite a bit of
time trying to track down what should be a simple answer and, no luck.
Anyway...

I'm trying to create a simple function that will match two form fields
against each other, e.g. Email equals Repeat Email.  The following
function seems to work, however, I'm a little uncomfortable because I don't
understand it.  Specifically, I don't understand why returning $str1 by
itself (or $str2 by itself) makes it work.

-
/* checks two fields against each other to make sure they match and if they
don't match it throws an error message into the $err_text array */

function CheckMatch($str1, $str2, $name)
{
global $err_text;
$match = ($str1 == $str2);
if ($match != true)
{
$err_text[] = $name must match.;
}
return $str1;
}
-

Any help is appreciated!  Thanks!

Jeff


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




[PHP] what does this mean in plain english?

2002-05-17 Thread Jeff Field

Hi. I'm fairly new to PHP and programming in general.  I'm learning mostly
by deconstructing what others have written...but even though I have plenty
of PHP books and have searched the Internet high and low, I'm stumped by the
exact meaning in the following function of what the question mark's (?)
and colon's (:), mean and do?

BTW, I'm not looking for an explanation of the function; just what the
question mark's and colon's mean in plain english, so I'll know how to use
them in other places.  Thanks!

Jeff

--
function GetSQLValueString($theValue, $theType)
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
case text:
  $theValue = ($theValue != ) ? ' . $theValue . ' : NULL;
  break;
case int:
  $theValue = ($theValue != ) ? intval($theValue) : NULL;
  break;
  }
  return $theValue;
}
--


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