OSEC

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 4 Jul 2004 16:14:54 -0000 Issue 2857

php-general-digest-helplists.php.net
Date: Sun Jul 04 2004 - 11:14:54 CDT


php-general Digest 4 Jul 2004 16:14:54 -0000 Issue 2857

Topics (messages 189657 through 189667):

user-defined superglobals
        189657 by: Michael Collins
        189658 by: Michael Gale
        189659 by: John W. Holmes
        189660 by: Jason Barnett
        189661 by: Michael Collins
        189662 by: Jason Barnett
        189665 by: Steve Douville

User Logon Procedure Fails
        189663 by: Harlequin
        189666 by: Torsten Roehr

Re: Obtain NT Logon
        189664 by: Harlequin

Unable to retrieve value from database and echo on screen
        189667 by: Harlequin

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


I am relatively new at PHP and wondering why there is no mechanism to
create user-defined superglobals? For example in ASP.Net I can setup
a global.asa to define database connections or any named value I want
to be available anywhere in an application. It would be great to have
something like that in PHP.

--
Michael
__
||| Michael Collins
||| Kuwago Inc
||| Singapore and Seattle USA

attached mail follows:


Hello,

        I am not a programmer so I do not know if you can create a "superglobal
variable". I am sure there is a problem with this ... any ways I user:

"require("db_access.php");"

at the top of all my pages that require db access for a application that
way the db access gets set on a per page bases. Which would be safe then
a superglobal one.

Michael.

On Sun, 4 Jul 2004 14:22:09 +0800
Michael Collins <listskuwago.com> wrote:

> I am relatively new at PHP and wondering why there is no mechanism to
> create user-defined superglobals? For example in ASP.Net I can setup
> a global.asa to define database connections or any named value I want
> to be available anywhere in an application. It would be great to have
> something like that in PHP.
>
> --
> Michael
> __
> ||| Michael Collins
> ||| Kuwago Inc
> ||| Singapore and Seattle USA
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

attached mail follows:


Michael Collins wrote:

> I am relatively new at PHP and wondering why there is no mechanism to
> create user-defined superglobals? For example in ASP.Net I can setup a
> global.asa to define database connections or any named value I want to
> be available anywhere in an application. It would be great to have
> something like that in PHP.

You can do the same thing with a PHP file and have it auto_prepended to
your scripts or just include() it yourself.

You can't make your own superglobals, but you can assign keys to the
existing ones, if you really want.

$_SERVER['MY_DATABASE_USER'] = 'user';
$_SERVER['MY_DATABASE_PASS'] = 'pass';

mysql_connect('localhost',$_SERVER['MY_DATABASE_USER'],$_SERVER['MY_DATABASE_PASS']);

etc...

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

attached mail follows:


About the only user-defined superglobals are constants. If you really
want to get the value of a global variable while inside of a function,
you could just use GLOBAL. Or if you REALLY wanted to, you could store
the variables in the $_SESSION superglobal array. But I'm curious, why
do you want superglobal-like access for your database connection?

Jason

attached mail follows:


At 2:57 AM -0400 7/4/04, John W. Holmes wrote:
>Michael Collins wrote:
>
>>I am relatively new at PHP and wondering why there is no mechanism
>>to create user-defined superglobals? For example in ASP.Net I can
>>setup a global.asa to define database connections or any named
>>value I want to be available anywhere in an application. It would
>>be great to have something like that in PHP.
>
>You can do the same thing with a PHP file and have it auto_prepended
>to your scripts or just include() it yourself.

I think I will opt for the strategy to prepend a file using the
auto_prepend_file directive in the php configuration file:

php_value auto_prepend_file /path/prepend.php

This was helpful (which I was able to find after getting the
terminology of auto_prepend):

http://www.zend.com/zend/spotlight/prepend.php

At 3:12 AM -0400 7/4/04, Jason Barnett wrote:
>About the only user-defined superglobals are constants. If you
>really want to get the value of a global variable while inside of a
>function, you could just use GLOBAL. Or if you REALLY wanted to,
>you could store the variables in the $_SESSION superglobal array.
>But I'm curious, why do you want superglobal-like access for your
>database connection?

In part, I am looking for a way to have a standardized library of
functions that are available everywhere without having to do an
include on every page. auto_prepend helps solve part of the issue
but the trouble with auto_prepend_file, or with including the library
on each page, is that php has to parse and process these pages for
each and every script. For performance reasons it would be much
better if certain values or code could be cached, as is the case with
the ASP global.asa file. If the files and scope was limited to an
application, or Web site, then a certain level of security should be
possible.

--
Michael
__
||| Michael Collins
||| Kuwago Inc
||| Singapore and Seattle USA

attached mail follows:


> every script. For performance reasons it would be much better if certain
> values or code could be cached, as is the case with the ASP global.asa
> file. If the files and scope was limited to an application, or Web site,
> then a certain level of security should be possible.
>

Well if you're looking for caching there are a couple of options
available. Zend and APC come to mind, YMMV.

attached mail follows:


Or if you wanted it to be pretty...

define('MY_DATABASE_USER', 'user');
define('MY_DATABASE_PASS', 'pass');

mysql_connect('localhost',MY_DATABASE_USER,MY_DATABASE_PASS);

----- Original Message -----
From: "John W. Holmes" <holmes072000charter.net>
To: "Michael Collins" <listskuwago.com>
Cc: <php-generallists.php.net>
Sent: Sunday, July 04, 2004 2:57 AM
Subject: Re: [PHP] user-defined superglobals

> Michael Collins wrote:
>
> > I am relatively new at PHP and wondering why there is no mechanism to
> > create user-defined superglobals? For example in ASP.Net I can setup a
> > global.asa to define database connections or any named value I want to
> > be available anywhere in an application. It would be great to have
> > something like that in PHP.
>
> You can do the same thing with a PHP file and have it auto_prepended to
> your scripts or just include() it yourself.
>
> You can't make your own superglobals, but you can assign keys to the
> existing ones, if you really want.
>
> $_SERVER['MY_DATABASE_USER'] = 'user';
> $_SERVER['MY_DATABASE_PASS'] = 'pass';
>
>
mysql_connect('localhost',$_SERVER['MY_DATABASE_USER'],$_SERVER['MY_DATABASE
_PASS']);
>
> etc...
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>

attached mail follows:


Another day another problem. This time it appears that users are able to
enter their details but I get a query execution error with the following
section of code:

/* Verify Login */
  $sql = "SELECT UserFirstName,UserID,UserPassword FROM RegisteredMembers
  WHERE UserID='$_POST[TXT_UserID]'";
  $result = mysql_query($sql) or die ("couldn't select database");
  $num = mysql_num_rows($result);
  if ($num == 1) //Login Name Was Found
  {
   $sql = "SELECT UserID FROM RegisteredMembers
      WHERE UserID='$_POST[TXT_UserID]'
        AND password=UserPassword('$_POST[TXT_UserPassword]')";
   $result2 = mysql_query($sql) or die("Couldn't execute query #2.");

The next to last line is bugging me though. "AND password= etc. because I
have a variable declared earlier in the logon page for TXT_UserPassword and
the UserPassword column exists but where in the hell is "password"...?

Is this another of MySQLs "on the fly" variables...?

--
-----------------------------
 Michael Mason
 Arras People
 www.arraspeople.co.uk
-----------------------------

attached mail follows:


"Harlequin" <michael.masonarraspeople.co.uk> wrote in message
news:20040704123631.62420.qmailpb1.pair.com...
> Another day another problem. This time it appears that users are able to
> enter their details but I get a query execution error with the following
> section of code:
>
> /* Verify Login */
> $sql = "SELECT UserFirstName,UserID,UserPassword FROM RegisteredMembers
> WHERE UserID='$_POST[TXT_UserID]'";

If your user id is of type int you don't need the quotes around the value.
But you definitely need quotes around your POST array key:
$sql = "SELECT UserFirstName,UserID,UserPassword FROM RegisteredMembers
WHERE UserID = $_POST['TXT_UserID']";

> $result = mysql_query($sql) or die ("couldn't select database");
> $num = mysql_num_rows($result);
> if ($num == 1) file://Login Name Was Found
> {
> $sql = "SELECT UserID FROM RegisteredMembers
> WHERE UserID='$_POST[TXT_UserID]'
> AND password=UserPassword('$_POST[TXT_UserPassword]')";

You already have the user id ($_POST[TXT_UserID]), so why select it?

Regards, Torsten

> $result2 = mysql_query($sql) or die("Couldn't execute query #2.");
>
> The next to last line is bugging me though. "AND password= etc. because I
> have a variable declared earlier in the logon page for TXT_UserPassword
and
> the UserPassword column exists but where in the hell is "password"...?
>
> Is this another of MySQLs "on the fly" variables...?
>
> --
> -----------------------------
> Michael Mason
> Arras People
> www.arraspeople.co.uk
> -----------------------------

attached mail follows:


Martin John is right.

I have used this facility with VB, VBA and VBS but not in PHP. However, the
principle is the same. Disable anonymous logins and use the code John is
suggesting and it should work a treat.

I'd recommend outputting this data to a TXT file or MySQL dbase also.

--
-----------------------------
 Michael Mason
 Arras People
 www.arraspeople.co.uk
-----------------------------
"John W. Holmes" <holmes072000charter.net> wrote in message
news:40E7525C.9080500charter.net...
> Manuel Lemos wrote:
>
> >> I have a web form with a field for username, this is a corporate site
> >> so will be the users NT logon. Would it be possible using PHP to obtain
> >> this information directly from the client pc?
> >
> > Assuming that you Web server is configured to require Windows NT domain
> > authentication for serving that PHP script, I suppose you can get the
> > user with GetEnv("LOGON_USER") .
>
> It's available directly in $_SESSION['LOGON_USER'], also. Like Manuel
> said, though, you have to turn off anonymous browsing in (assuming) IIS
> and enable NT authentication.
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com

attached mail follows:


I know, I know. Simple stuff to you guys, but I am learning more every day
and believe me - I won't be recommending Bill's software for web development
from now on :)

/* Select User's First Name From Table */
  $sql = "SELECT UserFirstName FROM RegisteredMembers WHERE
UserID='$_POST[TXT_UserID]'";
  $result5 = mysql_query($sql) or die ("couldn't select UserID from
database");
  $num = mysql_num_rows($result);

/* Welcome Registsred Member */
  echo "welcome to the registered members area ";

  echo ("$result");

I know iit has the data in there as I echoed an entire error statement and
the correct user was selected. I just need to echo a different field value
from those alraedy selected previously in the page.

--
-----------------------------
 Michael Mason
 Arras People
 www.arraspeople.co.uk
-----------------------------