Re: global to superglobal

From: Date: Sat, 11 Jan 2003 20:16:23 +0000
Subject: Re: global to superglobal
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-131278@lists.php.net to get a copy of this message
On Sunday 12 January 2003 03:45, pippo@bellnet.ca wrote: > I have a database that was created on an earlier version of PostgreSQL and > uses global variables with register_globals = on for php4. > I have migrated the database to postgresql-7.3.1 with mod_php-4.2.3 and > have set the register_globals to on. In order to use the default setting of > register_globals = off, I need to reprogram my php files. > I would appreciate some suggestions on how to go about modifying the code. > Is there a script that could be run on each file to convert to the > superglobals that would work with the register_globals off? If only it was that easy ;) The best thing to do is crank up error reporting to maximum (errors AND notices). You should see a lot of undefined or uninitialized variables notices/warnings. Find out where those variables are coming from (GET, POST or whatever) and change them appropriately. Eg you have a form with method=POST and a single text element called 'name'. Instead of using just $name in your code you need to use $_POST['name']. > I also need to know the exact syntax: for example, one current line is - > > include "$DOCUMENT_ROOT/../lib/somefile.conf"; > > Someone did suggest the following: > > include $_SERVER['DOCUMENT_ROOT'].'/../lib/somefile.conf'; > > however, there is a difference in the use of the quotation marks and I do > not understand the use of the . and .. It used to be that $DOCUMENT_ROOT was a predefined variable in the global scope. Thus you could use it directly in a string like in your first statement. Now DOCUMENT_ROOT can only be obtained from the $_SERVER array. Between strings and variables the period (.) acts as a concatenation operator. The second statement can be reformatted to make it clearer: $_SERVER['DOCUMENT_ROOT'] . '/../lib/somefile.conf'; Hopefully you can clearly see that the left side is equivalent to $DOCUMENT_ROOT and the right side is just a string. The '..' in the string on the right has nothing to with PHP, it's just the standard way to denote the parent directory. Single-quoted strings are literal strings, double-quoted strings does variable expansion. The second statement can also be rewritten as: "{$_SERVER['DOCUMENT_ROOT']}/../lib/somefile.conf"; -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Positive, adj.: Mistaken at the top of one's voice. -- Ambrose Bierce, "The Devil's Dictionary" */

« previous php.general (#131278) next »