|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general-digest-help
lists.php.net
Date: Fri Mar 14 2008 - 16:01:39 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 14 Mar 2008 21:01:39 -0000 Issue 5348
Topics (messages 271563 through 271619):
Re: Last Friday of every month
271563 by: Richard Heyes
271566 by: Eric Butera
271579 by: tedd
271583 by: Philip Thompson
271585 by: Philip Thompson
271590 by: Eric Butera
271598 by: tedd
Re: What's wrong the __autoload()?
271564 by: Zoltán Németh
271573 by: tedd
271577 by: Aschwin Wesselius
271580 by: tedd
Re: Sending multiple values from a form having same field names.
271565 by: Zoltán Németh
271567 by: Eric Butera
Re: Web host with SOAP
271568 by: Daniel Brown
Re: How to get error context
271569 by: It Maq
271570 by: Zoltán Németh
271571 by: It Maq
271574 by: Zoltán Németh
271591 by: It Maq
storing / processing login info (newbie stuff not in tutorials)
271572 by: good_times
271575 by: tedd
271576 by: Shawn McKenzie
271582 by: Philip Thompson
271599 by: tedd
Sendmail question
271578 by: nihilism machine
Is this the best way?
271581 by: Jason Pruim
271584 by: Dan Joseph
271586 by: TG
271587 by: Jason Pruim
271588 by: Jason Pruim
271589 by: Richard Heyes
271592 by: Eric Butera
271593 by: Shawn McKenzie
271594 by: Jason Pruim
271595 by: Jason Pruim
271597 by: TG
271606 by: Jason Pruim
271612 by: Jim Lucas
email issue
271596 by: nihilism machine
271600 by: Břrge Holen
PHP and #if
271601 by: Eric Gorr
271602 by: Břrge Holen
271603 by: Eric Gorr
271604 by: Dave Goodchild
271605 by: Stut
271607 by: Eric Gorr
271608 by: Shawn McKenzie
271609 by: Stut
271610 by: Eric Gorr
271611 by: Eric Gorr
271613 by: Shawn McKenzie
271614 by: André Medeiros
271615 by: Stut
271617 by: Andrés Robinet
Posting Summary for Week Ending 14 March, 2008: php-general
lists.php.net
271616 by: PostTrack [Dan Brown]
271618 by: Jason Pruim
Unable to create selectable TCP socket
271619 by: ros
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
VamVan wrote:
> Can you tell me how to do this ?
>
> suppose I have a date variable = '02/23/2008'
>
> i need to know if this is the last friday of february....
Work backwards from the 28th subtracting 86400 from your Unix timestamp
until you get to a Friday. Compare this with your variable.
--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
attached mail follows:
On Thu, Mar 13, 2008 at 9:39 PM, Andrés Robinet <agrobinet
bestplace.biz> wrote:
> > -----Original Message-----
> > From: VamVan [mailto:vamseevan
gmail.com]
> > Sent: Thursday, March 13, 2008 9:13 PM
> > To: php-general
lists.php.net
> > Subject: [PHP] Last Friday of every month
> >
> > Can you tell me how to do this ?
> >
> > suppose I have a date variable = '02/23/2008'
> >
> > i need to know if this is the last friday of february....
> >
> > let me know.
>
> My view...
>
> $strDate = '02/23/2008';
> //
> $intDate = strtotime($strDate);
> $numDaysInMonth = date('t', $intDate);
> $dayOfWeek = date('w', $intDate);
> $dayOfMonth = date('j', $intDate);
> If ($dayOfWeek == 5 && $numDaysInMonth - $dayOfMonth < 7) {
> echo "Friday Party!";
> } else {
> echo "Sorry dude, you missed it";
> }
>
> Btw, read the manual (and don't think to be so lucky to not found any bugs in my
> code).
>
> Regards,
>
> Rob(inet)
>
>
> Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
> 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 |
> TEL 954-607-4296 | FAX 954-337-2695 |
> Email: info
bestplace.net | MSN Chat: best
bestplace.net | SKYPE: bestplace |
> Web: bestplace.biz | Web: seo-diy.com
>
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Just FYI you can use the word "last friday" in strtotime. So really
you could check and see if the max day in a month is a friday and if
not fall back on last friday. I didn't test it but I just thought I'd
throw that out there.
erics:~ eric$ php -r "echo date('n/j/Y', strtotime('last friday'));"
3/7/2008
attached mail follows:
At 8:17 AM -0400 3/14/08, Eric Butera wrote:
>
>Just FYI you can use the word "last friday" in strtotime. So really
>you could check and see if the max day in a month is a friday and if
>not fall back on last friday. I didn't test it but I just thought I'd
>throw that out there.
>
>erics:~ eric$ php -r "echo date('n/j/Y', strtotime('last friday'));"
>3/7/2008
Eric:
When I read that, I went "Na, that can't be right" -- so I checked it.
You were right -- here it is:
http://webbytedd.com/b1/last-friday/
Thanks for the suggestion.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
On Mar 13, 2008, at 8:12 PM, VamVan wrote:
> Can you tell me how to do this ?
>
> suppose I have a date variable = '02/23/2008'
>
> i need to know if this is the last friday of february....
>
> let me know.
There are plenty of ways. Here's a couple:
OS X:
1. Finder > Applications > iCal (or Command-space for Spotlight, and
then type 'ical')
2. Click on Month (if not already selected)
3. Scroll to February
4. Look
Windows:
1. Double-click the clock in the task bar
2. Scroll to February
3. Look
HTH,
~Philip
PS... For a programmatic way, consult the PHP date functions...
attached mail follows:
On Mar 14, 2008, at 11:44 AM, Philip Thompson wrote:
> On Mar 13, 2008, at 8:12 PM, VamVan wrote:
>
>> Can you tell me how to do this ?
>>
>> suppose I have a date variable = '02/23/2008'
>>
>> i need to know if this is the last friday of february....
>>
>> let me know.
>
> There are plenty of ways. Here's a couple:
>
> OS X:
> 1. Finder > Applications > iCal (or Command-space for Spotlight, and
> then type 'ical')
> 2. Click on Month (if not already selected)
> 3. Scroll to February
> 4. Look
>
> Windows:
> 1. Double-click the clock in the task bar
> 2. Scroll to February
> 3. Look
Can't forget *nix:
1. Open a terminal and type the following
%> cal 2 2008
> HTH,
> ~Philip
>
> PS... For a programmatic way, consult the PHP date functions...
attached mail follows:
On Fri, Mar 14, 2008 at 11:57 AM, tedd <tedd.sperling
gmail.com> wrote:
> At 8:17 AM -0400 3/14/08, Eric Butera wrote:
> >
> >Just FYI you can use the word "last friday" in strtotime. So really
> >you could check and see if the max day in a month is a friday and if
> >not fall back on last friday. I didn't test it but I just thought I'd
> >throw that out there.
> >
> >erics:~ eric$ php -r "echo date('n/j/Y', strtotime('last friday'));"
> >3/7/2008
>
> Eric:
>
> When I read that, I went "Na, that can't be right" -- so I checked it.
>
> You were right -- here it is:
>
> http://webbytedd.com/b1/last-friday/
>
> Thanks for the suggestion.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hi Tedd,
Thanks for the writeup! You could streamline that a bit by using
getdate() and using the returned array values.
attached mail follows:
At 1:03 PM -0400 3/14/08, Eric Butera wrote:
>On Fri, Mar 14, 2008 at 11:57 AM, tedd <tedd.sperling
gmail.com> wrote:
>
> >
>> You were right -- here it is:
>>
> > http://webbytedd.com/b1/last-friday/
>>
>
>
>Hi Tedd,
>
>Thanks for the writeup! You could streamline that a bit by using
>getdate() and using the returned array values.
Streamline?
Anyway that does the job that I can understand works for me. :-)
Cheers,
tedd
PS: As they say in Perl "More than one way to do it." or something to
that affect -- it's been a long time since I programmed in Perl.
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
2008. 03. 14, pĂ©ntek keltezĂ©ssel 08.52-kor Aschwin Wesselius ezt Ărta:
> Robert Cummings wrote:
> > It works like follows...
> >
> > - $z asserts $a or claims $b
> > - $y disagrees with $a or $b or both and responds with rebuttal $h
> > and makes claims $c, $d, sometimes $e
> > - $z responds with rebuttal $i and often asserts a few other things
> > that well call $f, $g
> > - $x throws in $Q
> > - $w throws in $wtf
> > - $foo, $fee, and $fii join in
> > - $someone mentions $TLC
> > - $o calls us all immature
> > - $SJHSKJ mentions Nazis
> > - $x invokes Godwin's Law
> > - $y asserts Quirk's Exception
> > - $G_Zus resurrects point $d
> > - $nobody wins
> > - $r, $u, $stillWithMe
> >
>
> Aaah..... so we're just six points before the end of this thread? ;-)
threads like this live forever. after we all finish with it, sooner or
later someone will say something which will trigger its resurrection
greets,
Zoltán Németh
attached mail follows:
At 9:19 PM -0400 3/13/08, Robert Cummings wrote:
> - $z asserts $a or claims $b
> - $y disagrees with $a or $b or both and responds with rebuttal $h
> and makes claims $c, $d, sometimes $e
> - $z responds with rebuttal $i and often asserts a few other things
> that well call $f, $g
> - $x throws in $Q
> - $w throws in $wtf
> - $foo, $fee, and $fii join in
> - $someone mentions $TLC
> - $o calls us all immature
> - $SJHSKJ mentions Nazis
> - $x invokes Godwin's Law
> - $y asserts Quirk's Exception
> - $G_Zus resurrects point $d
> - $nobody wins
> - $r, $u, $stillWithMe
>
>Cheers,
>Rob.
Aha, you lose. You were the first to mention Nazis. :-)
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
tedd wrote:
> At 9:19 PM -0400 3/13/08, Robert Cummings wrote:
>> - $z asserts $a or claims $b
>> - $y disagrees with $a or $b or both and responds with rebuttal $h
>> and makes claims $c, $d, sometimes $e
>> - $z responds with rebuttal $i and often asserts a few other things
>> that well call $f, $g
>> - $x throws in $Q
>> - $w throws in $wtf
>> - $foo, $fee, and $fii join in
>> - $someone mentions $TLC
>> - $o calls us all immature
>> - $SJHSKJ mentions Nazis
>> - $x invokes Godwin's Law
>> - $y asserts Quirk's Exception
>> - $G_Zus resurrects point $d
>> - $nobody wins
>> - $r, $u, $stillWithMe
>>
>> Cheers,
>> Rob.
>
> Aha, you lose. You were the first to mention Nazis. :-)
Hey, at least I've learned something today. I thought he was joking
about Godwin's Law and whatever. But it really exists! Nice to know.
--
Aschwin Wesselius
/'What you would like to be done to you, do that to the other....'/
attached mail follows:
At 4:24 PM +0100 3/14/08, Aschwin Wesselius wrote:
>>tedd wrote:
>>At 9:19 PM -0400 3/13/08, Robert Cummings wrote:
>>>
>>> - $SJHSKJ mentions Nazis
>>Aha, you lose. You were the first to mention Nazis. :-)
>>
>Hey, at least I've learned something today. I thought he was joking
>about Godwin's Law and whatever. But it really exists! Nice to know.
Once you lose a valid argument, because you happen to use Hitler as a
bad example, you learn to never use it again. It's a stupid "Law",
but too many use it.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
2008. 03. 14, pĂ©ntek keltezĂ©ssel 14.08-kor Suamya Srivastava ezt Ărta:
> Hi,
>
> How can I send multiple values from a form to be stored in a database, as
> name of the fields is the same?
>
> For example:
>
> <?php
> foreach ($field_data as $field) {
>
> $field_name=$field["field_name"];
> $field_id=$field["field_id"];
> $datatype=$field["datatype_name"];
>
> ?>
> <input type="hidden" name="field_id" value="<?php echo $field_id;?>" />
> <tr>
> <td><strong><?php echo $field_name;?><strong></td>
> <?php
> if ($datatype=="text" || $datatype=="integer") {
> echo "<td><input type=\"text\" name=\"field_data\"></td>";
make field_data an array indexed by field_id
<input type="text" name="field_data[<?php echo $field_id; ?>]"
greets,
Zoltán Németh
> }
> elseif ($datatype=="textarea") {
> echo "<td><textarea rows=\"10\" cols=\"100\"
> name=\"field_data\"></textarea><br></td>";
> }
> echo "</tr>";
> }
> ?>
>
> This creates a form with field names and text box or textarea box next to
> each field name depending on the datatype. After the user enters the
> values in the text or textarea and clicks submit, the values should get
> stored in a database. But what is happening is that only the value entered
> in the last field of the form is getting entered into the database.
> This code is embedded in an application which is having an inbuilt
> structure of taking the values from a form in a hash. Since key is the
> same (i.e. field_id) everytime, the value gets overwritten and only the
> last value gets stored in db. But I am not able to work out a solution for
> this.
> I hope I am able to make my problem clear enough.
>
> Thanks,
> Suamya.
>
>
>
>
> -----------------------------------------------------------------------------
> DISCLAIMER:-
> "The information in this e-mail is confidential, and is intended
> solely for the addressee or addressees. If you are not the intended recipient,
> please delete the mail and kindly notify the sender of misdelivery. Any
> unauthorised use or disclosure of the contents of the mail is not permitted
> and may be unlawful."
> -----------------------------------------------------------------------------
>
> "Scanned By MailScanner"
>
>
attached mail follows:
On Fri, Mar 14, 2008 at 6:02 AM, Zoltán Németh <znemeth
alterationx.hu> wrote:
> 2008. 03. 14, pĂ©ntek keltezĂ©ssel 14.08-kor Suamya Srivastava ezt Ărta:
>
> > Hi,
> >
> > How can I send multiple values from a form to be stored in a database, as
> > name of the fields is the same?
> >
> > For example:
> >
> > <?php
> > foreach ($field_data as $field) {
> >
> > $field_name=$field["field_name"];
> > $field_id=$field["field_id"];
> > $datatype=$field["datatype_name"];
> >
> > ?>
> > <input type="hidden" name="field_id" value="<?php echo $field_id;?>" />
> > <tr>
> > <td><strong><?php echo $field_name;?><strong></td>
> > <?php
> > if ($datatype=="text" || $datatype=="integer") {
> > echo "<td><input type=\"text\" name=\"field_data\"></td>";
>
> make field_data an array indexed by field_id
>
> <input type="text" name="field_data[<?php echo $field_id; ?>]"
>
> greets,
> Zoltán Németh
>
>
>
> > }
> > elseif ($datatype=="textarea") {
> > echo "<td><textarea rows=\"10\" cols=\"100\"
> > name=\"field_data\"></textarea><br></td>";
> > }
> > echo "</tr>";
> > }
> > ?>
> >
> > This creates a form with field names and text box or textarea box next to
> > each field name depending on the datatype. After the user enters the
> > values in the text or textarea and clicks submit, the values should get
> > stored in a database. But what is happening is that only the value entered
> > in the last field of the form is getting entered into the database.
> > This code is embedded in an application which is having an inbuilt
> > structure of taking the values from a form in a hash. Since key is the
> > same (i.e. field_id) everytime, the value gets overwritten and only the
> > last value gets stored in db. But I am not able to work out a solution for
> > this.
> > I hope I am able to make my problem clear enough.
> >
> > Thanks,
> > Suamya.
> >
> >
> >
> >
> > -----------------------------------------------------------------------------
> > DISCLAIMER:-
> > "The information in this e-mail is confidential, and is intended
> > solely for the addressee or addressees. If you are not the intended recipient,
> > please delete the mail and kindly notify the sender of misdelivery. Any
> > unauthorised use or disclosure of the contents of the mail is not permitted
> > and may be unlawful."
> > -----------------------------------------------------------------------------
> >
> > "Scanned By MailScanner"
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Since Zoltán give you the answer I might give you another fish. Which
one is more readable:
<input type="hidden" name="field_id" value="<?php echo $field_id;?>" />
<tr>
<td><strong><?php echo $field_name;?><strong></td>
<?php
if ($datatype=="text" || $datatype=="integer") {
echo "<td><input type=\"text\" name=\"field_data\"></td>";
}
elseif ($datatype=="textarea") {
echo "<td><textarea rows=\"10\" cols=\"100\"
name=\"field_data\"></textarea><br></td>";
}
echo "</tr>";
}
?>
<input type="hidden" name="field_id" value="<?php echo
htmlspecialchars($field_id); ?>" />
<tr>
<td><strong><?php echo htmlspecialchars($field_name); ?><strong></td>
<?php if ($datatype=="text" || $datatype=="integer"): ?>
<td><input type="text" name="field_data"></td>
<?php elseif ($datatype=="textarea"): ?>
<td>
<textarea rows="10" cols="100" name="field_data"></textarea>
<br>
</td>
<?php endif; ?>
</tr>
attached mail follows:
On Thu, Mar 13, 2008 at 10:53 PM, Shawn McKenzie <nospam
mckenzies.net> wrote:
> >>
> > Ooooooooooo... I want SUDO!
>
> ALL = NOPASSWD: ALL
>
> please!
Which is exactly why you get the following FANTASTIC package!
* No shell access
* No databases
* No scripting support
* No FTP access
* 500K shared web space (additional 500K blocks are just $7.99)
* A free
gmail.com address
* No tech support
* No crons
* No SSI
* No SSL
* 5MB transfer per month (additional 1MB blocks are only $4.99)
All for the exclusive Internet price created just for you: $99.99
per month with a $99 one-time setup fee and $7/mo. account maintenance
fee. ;-P
All kidding aside, it's rather reminiscent of the pioneering days
of the web hosting industry. Check it out on the Internet Archive.
--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283
attached mail follows:
Hi,
I maid the modifications you suggested. For the error
context when i display it, it gives a lot of
information, but not easy to understand how the array
is structured. If somebody knows about a site
explaining how to access the context it would be
great.
I also modified the error reporting to E_ALL as you
suggested. Now an other question arise: For the
connection to the database if i put a wrong username
or password the error is reported automatically to the
function that i defined as the error handling
function, but for the next statement (see code below)
if i put a wrong database name the error is not
reported automatically, i have to trigger it using
triger_error. So i'm wondering if there are some rules
that can help me know if an error will be reported
automatically or not. here is my code after
modification:
<?php
function error_handler($errno, $errstr, $filename,
$lineno, $errcontext)
{
echo "handling reported error<br>";
switch($errno) {
case E_USER_ERROR: $type = "E_USER_ERROR";break;
case E_USER_WARNING: $type =
"E_USER_WARNING";break;
case E_USER_NOTICE: $type = "E_USER_NOTICE";break;
case E_ERROR: $type = "E_ERROR";break;
case E_WARNING: $type = "E_WARNING";break;
case E_PARSE: $type = "E_PARSE";break;
case E_NOTICE: $type = "E_NOTICE";break;
case E_CORE_ERROR: $type = "E_CORE_ERROR";break;
case E_CORE_WARNING: $type =
"E_CORE_WARNING";break;
case E_COMPILE_ERROR: $type =
"E_COMPILE_ERROR";break;
case E_STRICT: $type = "E_STRICT";break;
case E_COMPILE_WARNING: $type =
"E_COMPILE_WARNING";break;
case E_RECOVERABLE_ERROR: $type =
"E_RECOVERABLE_ERROR";break;
default: echo "<br>This is an error not listed";
}
$str = "";
$str .= "<br><br>ERROR TYPE: ". $type;
$str .= "<br><br>ERROR Number: ". $errno;
$str .= "<br>ERROR MESSAGE: ". $errstr;
$str.= "<br>File: ". $filename;
$str.= "<br>Line number: ". $lineno;
echo $str;
echo "Context: <br>";
print_r($errcontext);
}
echo "<h1>Testing set_error_handler</h1>";
error_reporting(E_ALL);
set_error_handler('error_handler');
mysql_connect("localhost", "admin", "admin");
mysql_select_db("wrongdb") or trigger_error("wrong
database");
?>
--- Jim Lucas <lists
cmsws.com> wrote:
> It Maq wrote:
> > Hi,
> >
> > i need help because I'm unable to retrieve error's
> context. Below is the code that is working perfectly
> except the context that is not displayed:
> >
> > <?php
> > function error_handler($errno, $errstr,
> $filename, $lineno, $errcontext)
> > {
> >
>
> try doing a print_r($errcontext) here and see what
> you get?
>
> maybe the zero index does not exist.
>
> >
> > $str = "";
> > $str .= "<br><br>ERROR Number: ". $errno;
> > $str .= "<br>ERROR MESSAGE: ". $errstr;
> > $str.= "<br>File: ". $filename;
> > $str.= "<br>Line number: ". $lineno;
> > $str.= "<br>Context: ". $errcontext[0];
> > echo $str;
> >
> >
> > }
> >
> > echo "<h1>Testing set_error_handler</h1>";
> >
>
> I have always used
> error_reporting(E_ALL);
> instead of this.
> > error_reporting(0);
> > set_error_handler('error_handler');
> > ini_set('error_reporting', 0);
>
> I have never seen the above line before. This and
> the error_reporting(0) would
> probably suppress all error messages generated by
> PHP. Double check these
> settings and make sure the you can still trigger an
> error with trigger_error()
> if you have error_reporting() turned off.
>
> >
> > //trigger_error("The string for testing the
> error", E_USER_WARNING);
> > $ourFileName = "testFile.txt";
> > $fh = fopen($ourFileName, 'X');// or die("Can't
> open file");
> > fclose($fh);
> >
> >
> > ?>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
attached mail follows:
2008. 03. 14, pĂ©ntek keltezĂ©ssel 07.20-kor It Maq ezt Ărta:
> So i'm wondering if there are some rules
> that can help me know if an error will be reported
> automatically or not.
there is no general rule for that. you have to check the manual for each
function, some of them just returns false on error, others throw
warnings/notices/errors...
greets,
Zoltán Németh
attached mail follows:
For example "mysql_connect" reprted automatically the
error but in the manual
http://us3.php.net/manual/en/function.mysql-connect.php
all they give as information is the return: "Returns
a MySQL link identifier on success, or FALSE on
failure.", where can i see if it throws an error, and
when you say throwing do you mean that i can catch the
error without throwing it myself?
--- Zoltán Németh <znemeth
alterationx.hu> wrote:
> 2008. 03. 14, péntek keltezéssel 07.20-kor It Maq
> ezt írta:
> > So i'm wondering if there are some rules
> > that can help me know if an error will be reported
> > automatically or not.
>
> there is no general rule for that. you have to check
> the manual for each
> function, some of them just returns false on error,
> others throw
> warnings/notices/errors...
>
> greets,
> Zoltán Németh
>
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
attached mail follows:
2008. 03. 14, pĂ©ntek keltezĂ©ssel 07.40-kor It Maq ezt Ărta:
> For example "mysql_connect" reprted automatically the
> error but in the manual
> http://us3.php.net/manual/en/function.mysql-connect.php
> all they give as information is the return: "Returns
> a MySQL link identifier on success, or FALSE on
> failure.", where can i see if it throws an error, and
> when you say throwing do you mean that i can catch the
> error without throwing it myself?
hmm actually what error did mysql_connect throw?
because if it just fails connecting, it returns false. on the other
hand, if you provide it wrong arguments (e.g. less arguments, or wrong
data type, or whatever) that raises a php error and the function does
not even run.
this is true for most functions which return false on error. the
returning false means there was some error with the action itself, while
php errors are raised when the action can not be executed because of
some error in the code itself.
greets,
Zoltán Németh
>
> --- Zoltán Németh <znemeth
alterationx.hu> wrote:
>
> > 2008. 03. 14, péntek keltezéssel 07.20-kor It Maq
> > ezt Ărta:
> > > So i'm wondering if there are some rules
> > > that can help me know if an error will be reported
> > > automatically or not.
> >
> > there is no general rule for that. you have to check
> > the manual for each
> > function, some of them just returns false on error,
> > others throw
> > warnings/notices/errors...
> >
> > greets,
> > Zoltán Németh
> >
> >
>
>
>
> ____________________________________________________________________________________
> Never miss a thing. Make Yahoo your home page.
> http://www.yahoo.com/r/hs
>
>
attached mail follows:
Here is the error message captured by my error
handling function:
mysql_connect() [function.mysql-connect]: Access
denied for user 'admin'
'localhost' (using password:
YES)
i put a wrong password and username
--- Zoltán Németh <znemeth
alterationx.hu> wrote:
> 2008. 03. 14, péntek keltezéssel 07.40-kor It Maq
> ezt írta:
> > For example "mysql_connect" reprted automatically
> the
> > error but in the manual
> >
>
http://us3.php.net/manual/en/function.mysql-connect.php
> > all they give as information is the return:
> "Returns
> > a MySQL link identifier on success, or FALSE on
> > failure.", where can i see if it throws an error,
> and
> > when you say throwing do you mean that i can catch
> the
> > error without throwing it myself?
>
> hmm actually what error did mysql_connect throw?
> because if it just fails connecting, it returns
> false. on the other
> hand, if you provide it wrong arguments (e.g. less
> arguments, or wrong
> data type, or whatever) that raises a php error and
> the function does
> not even run.
> this is true for most functions which return false
> on error. the
> returning false means there was some error with the
> action itself, while
> php errors are raised when the action can not be
> executed because of
> some error in the code itself.
>
> greets,
> Zoltán Németh
>
> >
> > --- Zoltán Németh <znemeth
alterationx.hu> wrote:
> >
> > > 2008. 03. 14, péntek keltezéssel 07.20-kor It
> Maq
> > > ezt írta:
> > > > So i'm wondering if there are some rules
> > > > that can help me know if an error will be
> reported
> > > > automatically or not.
> > >
> > > there is no general rule for that. you have to
> check
> > > the manual for each
> > > function, some of them just returns false on
> error,
> > > others throw
> > > warnings/notices/errors...
> > >
> > > greets,
> > > Zoltán Németh
> > >
> > >
> >
> >
> >
> >
>
____________________________________________________________________________________
> > Never miss a thing. Make Yahoo your home page.
> > http://www.yahoo.com/r/hs
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
attached mail follows:
1. instead of typing: $conn=ocilogon("usrname","passwrd","db");
can i save this info in a file and have my php script either include or call
it when it needs to make a db connection? what would that look like? i may
want to point my app to a test db at some point & it would be nice to only
change it in one place.
2. i see an example where a form in a login.html submits to "authcheck.php"
but authcheck.php just prints ('User not found in LDAP' or 'error occured'
or 'success'). how can authcheck.php redirect the user to... say.. BACK to
the login.html and tell it "yes or no" and then have login.html either
direct the user to a different data entry page (if the login was good), or
display "sorry, try again" - all from the 1 form's "submit"
thanx in advance,
mike.
--
View this message in context: http://www.nabble.com/storing---processing-login-info-%28newbie-stuff-not-in-tutorials%29-tp16048165p16048165.html
Sent from the PHP - General mailing list archive at Nabble.com.
attached mail follows:
At 8:01 AM -0700 3/14/08, good_times wrote:
>1. instead of typing: $conn=ocilogon("usrname","passwrd","db");
>can i save this info in a file and have my php script either include or call
>it when it needs to make a db connection? what would that look like? i may
>want to point my app to a test db at some point & it would be nice to only
>change it in one place.
Use:
include('config.php');
Where:
$usrname = 'username';
$passwrd = 'password';
$db = 'mydB';
In your script
include('config.php');
$conn=ocilogon($usrname,$passwrd,$db);
>2. i see an example where a form in a login.html submits to "authcheck.php"
>but authcheck.php just prints ('User not found in LDAP' or 'error occured'
>or 'success'). how can authcheck.php redirect the user to... say.. BACK to
>the login.html and tell it "yes or no" and then have login.html either
>direct the user to a different data entry page (if the login was good), or
>display "sorry, try again" - all from the 1 form's "submit"
If ($auth != true)
{
header('Location: http://www.example.com/login.html');
}
It's all in the manuals.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
good_times wrote:
> 1. instead of typing: $conn=ocilogon("usrname","passwrd","db");
> can i save this info in a file and have my php script either include or call
> it when it needs to make a db connection? what would that look like? i may
> want to point my app to a test db at some point & it would be nice to only
> change it in one place.
>
> 2. i see an example where a form in a login.html submits to "authcheck.php"
> but authcheck.php just prints ('User not found in LDAP' or 'error occured'
> or 'success'). how can authcheck.php redirect the user to... say.. BACK to
> the login.html and tell it "yes or no" and then have login.html either
> direct the user to a different data entry page (if the login was good), or
> display "sorry, try again" - all from the 1 form's "submit"
>
> thanx in advance,
> mike.
1. Normally you would have a file that is included in every file or most
files that does certain things like setup the db connection, etc...
This file can also include other files based upon some other logic that
you define, but a simple example would be to include('db_config.php');
in your pages:
db_config.php
$db_username = 'myusername';
$db_password = 'somepassword';
$db_name = 'mydb';
Then you can use those vars in your code.
2. Just have the login.html form submit to itself. At the top of the
file check to see if it is a POST request and if so check the user
credentials, set a session var that shows that they are loggedin and use
header() to redirect to the correct page.
-Shawn
attached mail follows:
On Mar 14, 2008, at 10:15 AM, tedd wrote:
> At 8:01 AM -0700 3/14/08, good_times wrote:
>> 1. instead of typing: $conn=ocilogon("usrname","passwrd","db");
>> can i save this info in a file and have my php script either
>> include or call
>> it when it needs to make a db connection? what would that look
>> like? i may
>> want to point my app to a test db at some point & it would be nice
>> to only
>> change it in one place.
>
> Use:
>
> include('config.php');
>
> Where:
>
> $usrname = 'username';
> $passwrd = 'password';
> $db = 'mydB';
>
> In your script
>
> include('config.php');
> $conn=ocilogon($usrname,$passwrd,$db);
>
>
>
>> 2. i see an example where a form in a login.html submits to
>> "authcheck.php"
>> but authcheck.php just prints ('User not found in LDAP' or 'error
>> occured'
>> or 'success'). how can authcheck.php redirect the user to... say..
>> BACK to
>> the login.html and tell it "yes or no" and then have login.html
>> either
>> direct the user to a different data entry page (if the login was
>> good), or
>> display "sorry, try again" - all from the 1 form's "submit"
>
> If ($auth != true)
> {
> header('Location: http://www.example.com/login.html');
exit;
This will potentially save you some headaches.... Read more at:
http://php.net/header
> }
>
> It's all in the manuals.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
HTH,
~Philip
"Personally, most of my web applications do not have to factor 13.7
billion years of space drift in to the calculations, so PHP's rand
function has been great for me..." ~S. Johnson
attached mail follows:
At 11:38 AM -0500 3/14/08, Philip Thompson wrote:
>On Mar 14, 2008, at 10:15 AM, tedd wrote:
>>At 8:01 AM -0700 3/14/08, good_times wrote:
>>>2. i see an example where a form in a login.html submits to "authcheck.php"
>>>but authcheck.php just prints ('User not found in LDAP' or 'error occured'
>>>or 'success'). how can authcheck.php redirect the user to... say.. BACK to
>>>the login.html and tell it "yes or no" and then have login.html either
>>>direct the user to a different data entry page (if the login was good), or
>>>display "sorry, try again" - all from the 1 form's "submit"
>>
>>If ($auth != true)
>> {
>> header('Location: http://www.example.com/login.html');
>
>exit;
>
>This will potentially save you some headaches.... Read more at:
>
>http://php.net/header
>
Yeah, you're right. But I didn't see headaches = OFF in the OP's question. :-)
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
attached mail follows:
I have a link that i want to use as the body of an html email. here
is the code i use:
// Notify about comments
public function emailComment($Link, $ID) {
$mail = new SendMail();
$mail->SetCharSet("ISO-8859-1");
$mail->from("someone", "someone
someone.com");
$mail->to("someoneelse
someoneelse.com");
$mail->subject("New Comment!");
$str = '<a href="http://www.mysite.com/permalink.php?ID='.
$Link.'">Comment ID #'.$ID.'</a>';
$mail->text($str);
//$mail->attachment($fileName);
$mail->send();
Where link = a number.
the email that i get is:
So the email should be a link to: http://www.mysite.com/permalink.php?ID=120
but instead links to: http://www.mysite.com/permalink.php?ID%120
Here is the php sendmail library =
<?
class SendMail {
public $emailheader = "";
public $textheader = "";
public $textboundary = "";
public $emailboundary = "";
public $charset = "";
public $subject = "";
public $empfaenger = "";
public $attachment = array();
public $cc = array();
public $bcc = array();
public function __construct() {
$this->textboundary = uniqid(time());
$this->emailboundary = uniqid(time());
$this->charset = "ISO-8859-1";
}
public function SetCharSet($char) {
$this->charset = $char;
}
public function Validate_Email($emailAddress) {
if(!preg_match("/[a-z0-9_-]+(\.[a-z0-9_-]+)*
([0-9a-z][0-9a-
z-]*[0-9a-z]\.)+([a-z]{2,4})/i", $emailAddress)) {
die('Invalid Email Address: '.$emailAddress);
}
return $emailAddress;
}
public function from($name, $email) {
$this->emailheader .= 'From: '.$name.'<'.$email.'>'."\r\n";
}
public function to($to) {
$this->empfaenger = $this->Validate_Email($to);
}
public function cc($cc) {
$this->cc[] = $cc;
}
public function bcc($cc) {
$this->bcc[] = $cc;
}
public function makeMimeMail() {
if(count($this->cc) > 0) {
$this->emailheader .= 'Cc: ';
for($i=0; $i<count($this->cc); $i++) {
if($i > 0) $this->emailheader .= ',';
$this->emailheader .= $this->Validate_Email($this->cc[$i]);
}
$this->emailheader .= "\r\n";
}
if(count($this->bcc) > 0) {
$this->emailheader .= 'Bcc: ';
for($j=0;$j<count($this->bcc);$j++) {
if($j > 0) $this->emailheader .= ',';
$this->emailheader .= $this->Validate_Email($this->bcc[$j]);
}
$this->emailheader .= "\r\n";
}
$this->emailheader .= 'MIME-Version: 1.0'."\r\n";
}
public function subject($subject) {
$this->subject = $subject;
}
public function text($text) {
$this->textheader .= 'Content-Type: multipart/alternative;
boundary="'.$this->textboundary.'"'."\r\n\r\n";
$this->textheader .= '--'.$this->textboundary."\r\n";
$this->textheader .= 'Content-Type: text/plain; charset="'.$this-
>charset.'"'."\r\n";
$this->textheader .= 'Content-Transfer-Encoding: quoted-
printable'."\r\n\r\n";
$this->textheader .= strip_tags($text)."\r\n\r\n";
$this->textheader .= '--'.$this->textboundary."\r\n";
$this->textheader .= 'Content-Type: text/html; charset="'.$this-
>charset.'"'."\r\n";
$this->textheader .= 'Content-Transfer-Encoding: quoted-
printable'."\r\n\r\n";
$this->textheader .= '<html><body>'.$text.'</body></html>'."\r\n
\r\n";
$this->textheader .= '--'.$this->textboundary.'--'."\r\n\r\n";
}
public function attachment($fileName) {
if(is_file($fileName)) {
$attachment_header = '--'.$this->emailboundary."\r\n" ;
$attachment_header .= 'Content-Type: application/octet-stream;
name="'.basename($fileName).'"'."\r\n";
$attachment_header .= 'Content-Transfer-Encoding: base64'."\r\n";
$attachment_header .= 'Content-Disposition: attachment;
filename="'.basename($fileName).'"'."\r\n\r\n";
$file['inhalt'] = fread(fopen($fileName,"rb"),filesize($fileName));
$file['inhalt'] = base64_encode($file['inhalt']);
$file['inhalt'] = chunk_split($file['inhalt'],72);
$this->attachment[] = $attachment_header.$file['inhalt']."\r\n";
} else {
die('ERROR - Invalid Filename: "' . $fileName . "\r\n");
}
}
public function send() {
$this->makeMimeMail();
$header = $this->emailheader;
if(count($this->attachment)>0) {
$header .= 'Content-Type: multipart/mixed; boundary="'.$this-
>emailboundary.'"'."\r\n\r\n";
$header .= '--'.$this->emailboundary."\r\n";
$header .= $this->textheader;
if(count($this->attachment) > 0) $header .= implode("",$this-
>attachment);
$header .= '--'.$this->emailboundary.'--';
} else {
$header .= $this->textheader;
}
mail("$this->empfaenger",$this->subject,"",$header);
$this->deletememory();
}
public function deletememory() {
unset($this->emailheader);
unset($this->textheader);
unset($this->attachment);
}
}
?>
attached mail follows:
Hi everyone,
I am attempting to add a little error checking for a very simple login
system. The info is stored in a MySQL database, and I am using mysqli
to connect to it. I have it working with the solution provided below,
but I am wondering if this is the right way to do it or if there is a
better way?
My thinking with this is if more then 1 record is returned from the
database, then there is a issue... If only is returned then the
username/password matched and I can safely show them the info...
$rowcnt = mysqli_num_rows($loginResult);
if($rowcnt !="1"){
echo "Auth failed";
die("Auth failed... Sorry");
}else{
while($row1 = mysqli_fetch_array($loginResult)) {
$_SESSION['user'] = $row1['loginName'];
$_SESSION['loggedin'] = "YES";
$table = $row1['tableName'];
$adminLevel = $row1['adminLevel'];
$authenticated = "TRUE";
echo "<BR>authentication complete";
}
return Array($table, $authenticated, $adminLevel);
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim
raoset.com
attached mail follows:
>
> I am attempting to add a little error checking for a very simple login
> system. The info is stored in a MySQL database, and I am using mysqli
> to connect to it. I have it working with the solution provided below,
> but I am wondering if this is the right way to do it or if there is a
> better way?
>
>
>
I don't see anything wrong with that method. One thing I would suggest is
that you make username unique in your database if you want to avoid
duplicate results. But your way of checking is just fine as it is.
--
-Dan Joseph
"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."
attached mail follows:
I think the first thing I'd check is why you'd have more than one row being
returned. Is this a problem with some other part of the system? Bad data
import? Not checking for unique users when creating them? Something
like that.
If you do everything you can to prevent the possibility of multiple users,
then you can still check for multiple results if you want, maybe send an
email to yourself, but for the sake of not frustrating your users, just
take the first result and compare the login to that. The worst that'll
happen is they won't match and the user won't get logged in. Best case is
they get logged in and you won't get an annoyed user calling you.
-TG
----- Original Message -----
From: Jason Pruim <japruim
raoset.com>
To: PHP General List <php-general
lists.php.net>
Date: Fri, 14 Mar 2008 12:12:56 -0400
Subject: [PHP] Is this the best way?
> Hi everyone,
>
> I am attempting to add a little error checking for a very simple login
> system. The info is stored in a MySQL database, and I am using mysqli
> to connect to it. I have it working with the solution provided below,
> but I am wondering if this is the right way to do it or if there is a
> better way?
>
> My thinking with this is if more then 1 record is returned from the
> database, then there is a issue... If only is returned then the
> username/password matched and I can safely show them the info...
>
> $rowcnt = mysqli_num_rows($loginResult);
> if($rowcnt !="1"){
> echo "Auth failed";
> die("Auth failed... Sorry");
>
>
>
> }else{
> while($row1 = mysqli_fetch_array($loginResult)) {
> $_SESSION['user'] = $row1['loginName'];
> $_SESSION['loggedin'] = "YES";
> $table = $row1['tableName'];
> $adminLevel = $row1['adminLevel'];
> $authenticated = "TRUE";
> echo "<BR>authentication complete";
> }
> return Array($table, $authenticated, $adminLevel);
attached mail follows:
On Mar 14, 2008, at 12:45 PM, Dan Joseph wrote:
> I am attempting to add a little error checking for a very simple login
> system. The info is stored in a MySQL database, and I am using mysqli
> to connect to it. I have it working with the solution provided below,
> but I am wondering if this is the right way to do it or if there is a
> better way?
>
>
>
> I don't see anything wrong with that method. One thing I would
> suggest is that you make username unique in your database if you
> want to avoid duplicate results. But your way of checking is just
> fine as it is.
Hey Dan,
Thanks for the reply! I couldn't find any reason why it wouldn't work,
but just wanted someone else to look at it as well... I'm not the best
programmer yet... Or at all.. But I'm getting there!
Thanks for the tip about the username being unique.... I'll make that
change as well...
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim
raoset.com
attached mail follows:
On Mar 14, 2008, at 12:51 PM, TG wrote:
>
> I think the first thing I'd check is why you'd have more than one
> row being
> returned. Is this a problem with some other part of the system?
> Bad data
> import? Not checking for unique users when creating them?
> Something
> like that.
The username's will be unique... Still need to make that change to the
DB but they will be.
The main reason I'm doing it this way, is if I don't put in some kind
of a check on the authentication then it pops up a mysql error saying
that there is a problem with my syntax... instead of NOT logging them
in... So I thought if I checked to make sure that the query only
returned 1 row, it would match up and I could do some error checking
based on that...
>
>
> If you do everything you can to prevent the possibility of multiple
> users,
> then you can still check for multiple results if you want, maybe
> send an
> email to yourself, but for the sake of not frustrating your users,
> just
> take the first result and compare the login to that. The worst
> that'll
> happen is they won't match and the user won't get logged in. Best
> case is
> they get logged in and you won't get an annoyed user calling you.
>
>
> -TG
>
> ----- Original Message -----
> From: Jason Pruim <japruim
raoset.com>
> To: PHP General List <php-general
lists.php.net>
> Date: Fri, 14 Mar 2008 12:12:56 -0400
> Subject: [PHP] Is this the best way?
>
>> Hi everyone,
>>
>> I am attempting to add a little error checking for a very simple
>> login
>> system. The info is stored in a MySQL database, and I am using mysqli
>> to connect to it. I have it working with the solution provided below,
>> but I am wondering if this is the right way to do it or if there is a
>> better way?
>>
>> My thinking with this is if more then 1 record is returned from the
>> database, then there is a issue... If only is returned then the
>> username/password matched and I can safely show them the info...
>>
>> $rowcnt = mysqli_num_rows($loginResult);
>> if($rowcnt !="1"){
>> echo "Auth failed";
>> die("Auth failed... Sorry");
>>
>>
>>
>> }else{
>> while($row1 = mysqli_fetch_array($loginResult)) {
>> $_SESSION['user'] = $row1['loginName'];
>> $_SESSION['loggedin'] = "YES";
>> $table = $row1['tableName'];
>> $adminLevel = $row1['adminLevel'];
>> $authenticated = "TRUE";
>> echo "<BR>authentication complete";
>> }
>> return Array($table, $authenticated, $adminLevel);
>
>
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim
raoset.com
attached mail follows:
> $rowcnt = mysqli_num_rows($loginResult);
> if($rowcnt !="1"){
> echo "Auth failed";
> die("Auth failed... Sorry");
>
>
>
> }else{
> while($row1 = mysqli_fetch_array($loginResult)) {
> $_SESSION['user'] = $row1['loginName'];
> $_SESSION['loggedin'] = "YES";
Eww. Use booleans:
$_SESSION['loggedin'] = true;
> $table = $row1['tableName'];
> $adminLevel = $row1['adminLevel'];
> $authenticated = "TRUE";
Like above, I would advise using booleans (true/false) and not strings
(text):
$authenticated = true; // Note the lack of quote marks
--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
attached mail follows:
On Fri, Mar 14, 2008 at 1:02 PM, Richard Heyes <richardh
phpguru.org> wrote:
> > $rowcnt = mysqli_num_rows($loginResult);
> > if($rowcnt !="1"){
> > echo "Auth failed";
> > die("Auth failed... Sorry");
> >
> >
> >
> > }else{
> > while($row1 = mysqli_fetch_array($loginResult)) {
> > $_SESSION['user'] = $row1['loginName'];
> > $_SESSION['loggedin'] = "YES";
>
> Eww. Use booleans:
>
> $_SESSION['loggedin'] = true;
>
>
> > $table = $row1['tableName'];
> > $adminLevel = $row1['adminLevel'];
> > $authenticated = "TRUE";
>
> Like above, I would advise using booleans (true/false) and not strings
> (text):
>
> $authenticated = true; // Note the lack of quote marks
>
> --
> Richard Heyes
> Employ me:
> http://www.phpguru.org/cv
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Yes, if it is a lack of being able to see your value using print_r or
echo, then use var_dump().
attached mail follows:
Dan Joseph wrote:
>> I am attempting to add a little error checking for a very simple login
>> system. The info is stored in a MySQL database, and I am using mysqli
>> to connect to it. I have it working with the solution provided below,
>> but I am wondering if this is the right way to do it or if there is a
>> better way?
>>
>>
>>
> I don't see anything wrong with that method. One thing I would suggest is
> that you make username unique in your database if you want to avoid
> duplicate results. But your way of checking is just fine as it is.
>
To go along with this and making sure that usernames are unique, I would
LIMIT 1 on the query. With no LIMIT, if you have 300,000 users, then
the query will not stop if it matches the first user, it searches all
300,000. With LIMIT 1 it will stop on the first match.
-Shawn
attached mail follows:
On Mar 14, 2008, at 1:05 PM, Eric Butera wrote:
> On Fri, Mar 14, 2008 at 1:02 PM, Richard Heyes
> <richardh
phpguru.org> wrote:
>>>
>>
>
> Yes, if it is a lack of being able to see your value using print_r or
> echo, then use var_dump().
>
Seeing the value's and printing them arn't a problem... Just a hold
over from an old program I am rewriting now that I know more about
what I'm doing. Hopefully stream lining the entire thing!
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim
raoset.com
attached mail follows:
On Mar 14, 2008, at 1:15 PM, Shawn McKenzie wrote:
> Dan Joseph wrote:
>>> I am attempting to add a little error checking for a very simple
>>> login
>>> system. The info is stored in a MySQL database, and I am using
>>> mysqli
>>> to connect to it. I have it working with the solution provided
>>> below,
>>> but I am wondering if this is the right way to do it or if there
>>> is a
>>> better way?
>>>
>>>
>>>
>> I don't see anything wrong with that method. One thing I would
>> suggest is
>> that you make username unique in your database if you want to avoid
>> duplicate results. But your way of checking is just fine as it is.
>>
> To go along with this and making sure that usernames are unique, I
> would
> LIMIT 1 on the query. With no LIMIT, if you have 300,000 users, then
> the query will not stop if it matches the first user, it searches all
> 300,000. With LIMIT 1 it will stop on the first match.
Hi Shawn,
I do have a LIMIT 0,1 that didn't make it into the actual copy/paste.
Thanks though for the tip!
>
>
> -Shawn
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim
raoset.com
attached mail follows:
What error are you getting? Maybe there's some way to fix that too.
Just remember that errors and notices are like pain. It usually means
there's something wrong. If you're getting an error, there may be a better
way of doing waht you're doing.
Ideally, you should get zero results if there's no match in the user database.
Typically for a user lookup, you might do something like this:
SELECT <whatever> FROM usertable WHERE username = '<username>' AND password =
'<password>'
If you get zero results, then they don't exist OR they entered the wrong
password.
If you get more than one result, then you have a duplicate account.
If you have duplicate usernames, then you won't get multiple matches unless
the passwords are also duplicated.
Say, for example, you have a duplicated username but different passwords:
user: me
pass: pass1
user: me
pass: pass2
Then login will succeed if they use me/pass1 OR me/pass2 but each way,
you'll still only get one result from your db query.
btw.. before someone rails me for not mentioning security... typically you'd
store the passwords encrypted or hashed (one-way md5 or something) then you
encrypt or hash the password the same when the user is logging in and
compare them to the DB. That way, you don't store the password in
plaintext and you can still check to see if the right password is entered.
example:
user: me
pass: pass1
md5(pass1): laksro2i3 (fake md5.. lazy :)
user logs in with:
user: me
pass: pass1
system runs md5(pass1) and gets laksro2i3 again. it matches what's in the
DB, so therefore is the correct password.
Anyway.. main point is.. if you're getting errors, try to fix them. If
you're getting multiple results on your user check, you may have bad
input/uniqueness checking or you may be implementing your user system not
as logically as you could.
-TG
----- Original Message -----
From: Jason Pruim <japruim
raoset.com>
To: "TG" <tg-php
gryffyndevelopment.com>
Cc: "PHP General List" <php-general
lists.php.net>
Date: Fri, 14 Mar 2008 13:00:11 -0400
> On Mar 14, 2008, at 12:51 PM, TG wrote:
>
> The username's will be unique... Still need to make that change to the
> DB but they will be.
>
> The main reason I'm doing it this way, is if I don't put in some kind
> of a check on the authentication then it pops up a mysql error saying
> that there is a problem with my syntax... instead of NOT logging them
> in... So I thought if I checked to make sure that the query only
> returned 1 row, it would match up and I could do some error checking
> based on that...
attached mail follows:
On Mar 14, 2008, at 1:44 PM, TG wrote:
>
> What error are you getting? Maybe there's some way to fix that too.
The error I get without checking the row count is this:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'order by LName' at line 1
>
>
> Just remember that errors and notices are like pain. It usually means
> there's something wrong. If you're getting an error, there may be a
> better
> way of doing waht you're doing.
>
> Ideally, you should get zero results if there's no match in the user
> database.
>
> Typically for a user lookup, you might do something like this:
>
> SELECT <whatever> FROM usertable WHERE username = '<username>' AND
> password =
> '<password>'
Which is very simular to what I have:
$loginQuery = "SELECT * FROM current WHERE loginName='".$user."' AND
loginPassword='".$password."' LIMIT 0,1;";
$loginResult = mysqli_query($link1, $loginQuery) or die("Wrong data
supplied or database error" .mysqli_error($link1));
>
>
> If you get zero results, then they don't exist OR they entered the
> wrong
> password.
>
> If you get more than one result, then you have a duplicate account.
>
> If you have duplicate usernames, then you won't get multiple matches
> unless
> the passwords are also duplicated.
>
> Say, for example, you have a duplicated username but different
> passwords:
>
> user: me
> pass: pass1
>
> user: me
> pass: pass2
>
>
> Then login will succeed if they use me/pass1 OR me/pass2 but each
> way,
> you'll still only get one result from your db query.
>
>
> btw.. before someone rails me for not mentioning security...
> typically you'd
> store the passwords encrypted or hashed (one-way md5 or something)
> then you
> encrypt or hash the password the same when the user is logging in and
> compare them to the DB. That way, you don't store the password in
> plaintext and you can still check to see if the right password is
> entered.
Which I have complete with some $salt added :)
>
>
>
> example:
>
> user: me
> pass: pass1
> md5(pass1): laksro2i3 (fake md5.. lazy :)
>
> user logs in with:
>
> user: me
> pass: pass1
>
> system runs md5(pass1) and gets laksro2i3 again. it matches what's
> in the
> DB, so therefore is the correct password.
>
>
> Anyway.. main point is.. if you're getting errors, try to fix
> them. If
> you're getting multiple results on your user check, you may have bad
> input/uniqueness checking or you may be implementing your user
> system not
> as logically as you could.
It was the error, rather then multiple accounts that I'm checking for.
I'm not advanced enough in my programming ability to implement a true
multi user envriomnent where user1/pass1 is different from user1/
pass2 :)
>
>
> -TG
>
>
> ----- Original Message -----
> From: Jason Pruim <japruim
raoset.com>
> To: "TG" <tg-php
gryffyndevelopment.com>
> Cc: "PHP General List" <php-general
lists.php.net>
> Date: Fri, 14 Mar 2008 13:00:11 -0400
>
>> On Mar 14, 2008, at 12:51 PM, TG wrote:
>>
>> The username's will be unique... Still need to make that change to
>> the
>> DB but they will be.
>>
>> The main reason I'm doing it this way, is if I don't put in some kind
>> of a check on the authentication then it pops up a mysql error saying
>> that there is a problem with my syntax... instead of NOT logging
>> them
>> in... So I thought if I checked to make sure that the query only
>> returned 1 row, it would match up and I could do some error checking
>> based on that...