On Sat, 2005-05-14 at 19:34 -0700, Richard Lynch wrote:
> On Fri, October 14, 2005 11:33 am, Cima said:
> > i have my web site working something like this: in every php script i have
> > require(auth.php). this auth.php has my connection to my postgresql server
> > and database along with some other stuff i need for the user to be
> > authenticated to my web site. when i log on, this auth.php connects to the
> > dbserver and checks if my username and password are stored and then i go
> > to a home page. my connection is stored in $dbh.
> > what happens when i start moving through all these web pages (php
> > scripts), each requires auth.php, with respect to the connection? is a new
> > connection established for every web page i go into that uses my $dbh for
> > querying purposes or is it the same connection i originally made when i
> > first logged into the web site?
>
> You'll get a new connection on each page.
>
> Which is good, because database connections CANNOT be shared across page
> hits.
>
> If you use _pconnect, you can get a "refurbished" connection from the
> database instead of a truly new one. But there are "gotchas" with that,
> and I wouldn't recommend you jump into that without a lot more
> research/experience.
>
> I would suggest, however, that you put the database connection in a
> totally separate file from the auth.php, and require them separately.
>
> You may find more uses for your database some day, maybe even for pages
> that do NOT require authentication, and you'll more easily do that if you
> can just do:
> <?php require 'db_connect.php';?>
>
> For the pages that need authentication, you'd do:
> <?php
> require 'db_connect.php';
> require 'auth.php';
> ?>
-- Better yet:
file auth.php:
require_once 'db_connect.php';Ever since discovering the [require|include]_once I have wondered how I managed before... Hope this helps -- Jeff > You could also look into http://php.net/require_once, but I tend to find > that people who start off with that end up being sloppy coders and end up > having a whole rats' nest of includes with no real Plan behind them, which > cause problems in the long run. Just my opinion, and I'm bound to take > flak for it. > > -- > Like Music? > http://l-i-e.com/artists.htm > -- Jeffrey D. Means [EMAIL PROTECTED] Owner / CIO for MeansPC http://www.meanspc.com/ Custom Web Development For Your Needs. (970)308-1298 - The stupidity of a stupid person is exercised in a restricted field; the stupidity of an intelligent individual has a much broader diffusion, and far greater effect, aided as it is by the element of surprise. - WTO + WIPO = DMCA? http://www.anti-dmca.org - Fight Internet Censorship! http://www.eff.org = This is not about Napster or DVDs. It's about your Freedom. http://www.anti-dmca.org My Public PGP Key ID is: 0x81F00126 and available via: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x81F00126
signature.asc
Description: This is a digitally signed message part

