From: Rod K <rod@23net.net>
To: Seader, Cameron <CSeader@idahopower.com>
To: pgsql-php@postgresql.org
Subject: Re: HTTP_AUTH and SQL WHERE Clause
Date: Sun, 28 Sep 2003 09:53:35 -0400
Message-ID: <KNEPILBLIADCDMMPIKIKCEEKCOAA.rod@23net.net> (raw)
In-Reply-To: <71B8A8BEC516CF46835CA629156CF21163F5CE@bedford.idacorp.local>
> $sql = ("SELECT * FROM tbl_authenticate WHERE username =
> '$PHP_AUTH_USER' AND password = '$PHP_AUTH_PW'");
>
There's no need for the parens around the quoted value.
> The Problem is on the $sql line when i put in the string to do
> the Query with the WHERE clause having the $HTTP_AUTH_USER and
> $HTTP_AUTH_PW. When i change it to '$_SERVER['HTTP_AUTH_USER']'
> and '$_SERVER['HTTP_AUTH_PW']' it does not work and i get a parse error.
So the new assignment looks like this:
$sql= "SELECT * FROM tbl_authenticate WHERE username =
'$_SERVER['HTTP_AUTH_USER']' AND password = '$_SERVER['HTTP_AUTH_PW']'";
The problem is that PHP doesn't know what you are trying to do here.
"'$_SERVER['HTTP_AUTH_PW']'" could mean "'(the value of
$_SERVER)['HTTP_AUTH_PW']'" or what you intend. To get around that you need
to enclose array elements (as well as other complex type structures like
$myObject->property ) with braces (or place them outside the quoted value.
The former:
$sql= "SELECT * FROM tbl_authenticate WHERE username =
'{$_SERVER['HTTP_AUTH_USER']}' AND password = '{$_SERVER['HTTP_AUTH_PW']}'";
and the later:
$sql= "SELECT * FROM tbl_authenticate WHERE username =
'".$_SERVER['HTTP_AUTH_USER']."' AND password =
'".$_SERVER['HTTP_AUTH_PW']."'";
I prefer the later since it's a bit easier to read IMO.
HTH
Rod
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: rod@23net.net, CSeader@idahopower.com
Subject: Re: HTTP_AUTH and SQL WHERE Clause
In-Reply-To: <KNEPILBLIADCDMMPIKIKCEEKCOAA.rod@23net.net>
References: <71B8A8BEC516CF46835CA629156CF21163F5CE@bedford.idacorp.local> <KNEPILBLIADCDMMPIKIKCEEKCOAA.rod@23net.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox