Re: [PHP] Global Variables
session_start(); $_SESSION['somevar'] = foo; u could also check out pear's HTTP_Session package. On 28/04/2005, at 7:06 PM, Dan wrote: Hi all. I taught myself PHP before the frenzy over register_globals. After a reasonable break from the language, I'm back for more. I'm building a site where I'll be holding a lot of variables in memory for each session. How do I do that? Apparently I can't use session_register() if register_globals is turned off. I've read a little about the consequences of writing bad scripts with register_globals on ... I'm fine with this explanation. I agree that I don't want people injecting variables into my session. What I want is for ME to be able to set variables and remember them throughout the session. How do I do that? Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables
As far as I know, it's not true you can't use session variables if register_globals is off, the difference is that you must acces session variables using $_SESSION['variablename'], that's is an assurance that a session variable is a REAL session variable, and that it is not set using for example a faked form. hope this is a correct answer and it helps you, Giulio Il giorno 28/apr/05, alle 11:06 AM, Dan ha scritto: Hi all. I taught myself PHP before the frenzy over register_globals. After a reasonable break from the language, I'm back for more. I'm building a site where I'll be holding a lot of variables in memory for each session. How do I do that? Apparently I can't use session_register() if register_globals is turned off. I've read a little about the consequences of writing bad scripts with register_globals on ... I'm fine with this explanation. I agree that I don't want people injecting variables into my session. What I want is for ME to be able to set variables and remember them throughout the session. How do I do that? Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Cantoberon Multimedia srl http://www.cantoberon.it Tel. 06 39737052
Re: [PHP] Global Variables
Giulio wrote: As far as I know, it's not true you can't use session variables if register_globals is off, the difference is that you must acces session variables using ALWAYS CALL session_start() BEFORE TRYING TO USE THE $_SESSION SUPERGLOBAL! also I don't quite see the connection with register_globals, but anyway var sent by POST/GET can be found in the $_POST and $_GET superglobal vars $_SESSION['variablename'], that's is an assurance that a session variable is a REAL session variable, and that it is not set using for example a faked form. hope this is a correct answer and it helps you, Giulio Il giorno 28/apr/05, alle 11:06 AM, Dan ha scritto: Hi all. I taught myself PHP before the frenzy over register_globals. After a reasonable break from the language, I'm back for more. I'm building a site where I'll be holding a lot of variables in memory for each session. How do I do that? Apparently I can't use session_register() if register_globals is turned off. I've read a little about the consequences of writing bad scripts with register_globals on ... I'm fine with this explanation. I agree that I don't want people injecting variables into my session. What I want is for ME to be able to set variables and remember them throughout the session. How do I do that? Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Cantoberon Multimedia srl http://www.cantoberon.it Tel. 06 39737052 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables
Dan wrote: Hi all. I taught myself PHP before the frenzy over register_globals. After a reasonable break from the language, I'm back for more. I'm building a site where I'll be holding a lot of variables in memory for each session. How do I do that? Apparently I can't use session_register() if register_globals is turned off. I've read a little about the consequences of writing bad scripts with register_globals on ... I'm fine with this explanation. I agree that I don't want people injecting variables into my session. What I want is for ME to be able to set variables and remember them throughout the session. How do I do that? Use the super-global _SESSION array... session_start(); // -- Some code -- // $_SESSION['foo'] = 'bar'; -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global variables in a class? Nested classes VS inheritance...
Hi, Thursday, July 31, 2003, 1:30:54 AM, you wrote: amc Hello, amc I'm lookin for some tips on the best way to do this... amc I make a database connection outside of my classes... lets call it amc $myDBConnection. I need to use this connection in a class nested in a amc class... Was wondering the most efficient way of doing this? I don't want to amc create a new db connection in the class. I want to use the existing one... amc If no one has a better Idea I'll pass the connection through the constructor amc of the first class, and then again into the constructor of the nested amc class... then I can query and use the database connection as $this-myDBConnection Just wanted to avoid that because there's about 5 amc db connections I'll have to pass in... amc Any thoughts? Would it make things easyer if the base class inherited all amc nested classes instead of nesting them? amc Any help would be appreciated. amc Thanks amc -Dennis what I do is have a global array of classes and register each class like this: class a { function a(){ global $classes; $classes['a'] = $this; } } class b { var $a; function b(){ global $classes; if(isset($classes['a'])){ this-a = $classes['a']; }else{ $this-a = new a(); } } } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables
In terms of security, or in my opinion, good and proper coding, it is best to have no global variables. There is always a way to wrap variables that will be needed in local scopes. However, this philosophy is harder to practice than it is to preach. Code can get ugly when passing if you are not strong in your coding designing abilities. Sometime it just becomes easier to attempt to keep as much out of the global scope as possible and suffer the idea of some of them being globally available. That being said, if someone was to exploit a script that had global or local access to a variable storing database connection info, then the consequences could be drastic. Similar situations are easly applicable as well, with any crucial data or passwords etc. You should consider reading the section entitled, Security: New Input Mechanism here: http://www.php.net/release_4_1_0.php Regards, Jason k Larson Dara Dowd wrote: Is it better to pass variables through functions or to simply declare them as global within the function's scope? The variables in this particular case are things like MySQL database connections and tablenames. Thanks,Dara -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables
For this use globals, it would be painfull to pass everything. But you can also use some class that would keep track of such things. Dara Dowd wrote: Is it better to pass variables through functions or to simply declare them as global within the function's scope? The variables in this particular case are things like MySQL database connections and tablenames. Thanks,Dara -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global variables question
At 21:49 10.11.2002, Mathieu Dumoulin said: [snip] Hi, i got this project i'm building right now. It basically a core system to do adminsitrative modules for web sites. I got tons of classes that get created on call of a function like sql_setup(), frm_setup(). These functions create the objects from the classes so they can be used later in other objects...yada yada yada... Now my thing is, instead of always starting my method of an object with global sql_server; and global frm_builder, is there a way that these variables are declared as global automatically, just like i would get $_GET[], $_POST[] and so on, they are already global. I want to do this to simplify development since this project is going to be HUGE. And also it will facilitate debugging as i've been using global at a lot of places and when you forget one, PHP assumes the creation of a dummy variable messing up everything. [snip] Hi Mathieu, to begin with, if this project is HUGE as you said, try to avoid globals as good as you can - they're absolze poison for the readability, stability, and scalability of any application that extends a single source file with a couple of lines. Of course this is only MHO, I'm sure others will chime in here. I am currently working on an application core that's expected to work with a nice number of objects, and it is not feasible here to have objects a) global and simply not possible to have every part of the application using its own reference to the object instance. What I did is to create a container for objects and wrap it into a class I call CCache. As soon as an object gets instantiated it registers itself with the cache (being uniquely identified by Type and ID). Any part of the application simply calls the systemwide cache object with type and ID to retrieve a reference to the specific object it needs just now. I did a performance profiling on this system, and retrieving an object reference from the cache needs approx. 0.001 msec. Just to tell you, not even the cache object is global - there is a public wrapper function around it to return a reference to the global cache object. Currently we have approx. 85,000 lines of code, and absolutely no global variable of our own... -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
On Lun 04 Nov 2002 00:10, Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) if ($_GET[error_message]) Did you check on what $_GET contains? var_dump($_GET); Saludos... :-) -- Porqué usar una base de datos relacional cualquiera, si podés usar PostgreSQL? - Martín Marqués |[EMAIL PROTECTED] Programador, Administrador, DBA | Centro de Telematica Universidad Nacional del Litoral - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Global Variables Off
I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
Try single quotes... $_GET['test'] Paul wrote: I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Global Variables Off
Makes no difference..I tried them both -Original Message- From: John Nichel [mailto:jnichel;by-tor.com] Sent: Sunday, November 03, 2002 10:59 PM To: Paul Cc: 'Chris Shiflett'; [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off Try single quotes... $_GET['test'] Paul wrote: I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
I assume you mean that the echo statement I gave as an example shows this: The test variable is [] Right? If so, that is truly odd, especially considering you are using 4.2.3. I don't have a good answer for that ... Add this code to the top of your script to see if PHP thinks the client is passing any data at all: echo pre; print_r($_REQUEST); echo /pre; Chris Paul wrote: I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
Try these two simple tests, with the url test.php?test=foo HTML BODY ? print_r($_GET); ?br / ?=$_GET['test']? /BODY /HTML And show us the results. Justin on 04/11/02 1:54 PM, Paul ([EMAIL PROTECTED]) wrote: I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Global Variables Off
OK I guess I am closer = the variable is being passed as I tested but I guess is failing on the test: if (isset($_GET[error_message])) Thank you for all your help Paul -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 11:08 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off I assume you mean that the echo statement I gave as an example shows this: The test variable is [] Right? If so, that is truly odd, especially considering you are using 4.2.3. I don't have a good answer for that ... Add this code to the top of your script to see if PHP thinks the client is passing any data at all: echo pre; print_r($_REQUEST); echo /pre; Chris Paul wrote: I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
I think your machine is blasted - Find out an exorcist or a witch or move out to other program- - Original Message - From: Paul [EMAIL PROTECTED] To: 'John Nichel' [EMAIL PROTECTED] Cc: 'Chris Shiflett' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, November 04, 2002 3:02 PM Subject: RE: [PHP] Global Variables Off Makes no difference..I tried them both -Original Message- From: John Nichel [mailto:jnichel;by-tor.com] Sent: Sunday, November 03, 2002 10:59 PM To: Paul Cc: 'Chris Shiflett'; [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off Try single quotes... $_GET['test'] Paul wrote: I am passing it via URL as: http://example.org/test.php?test=foo When I do that call to $_GET[test] shows that variable is not set, however, when I run phpinfo() it shows value assigned to _GET. With no change in code, I turn global variables 'on' and the same page works.. Paul PS using php 4.2.3 -Original Message- From: Chris Shiflett [mailto:shiflett;php.net] Sent: Sunday, November 03, 2002 10:15 PM To: Paul Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Global Variables Off You didn't really tell us how you're passing data or what is not working. Try this. Create a test script called test.php that looks like this: ? echo pThe test variable is [ . $_GET[test] . ]/p; ? Assuming this script is located at http://example.org/test.php, access this page using a URL like this: http://example.org/test.php?test=foo Chris Paul wrote: Ok, I have turned global vars off and I have replaced my old $HTTP_GET_VARS with $_GET[] but I seem to not get the values passed. I run the phpinfo and I see the variables being stored as _GET[variable_name] Is calling $_GET[variable_name] correct? If so, why would I not get the value? I use it in the following statement (checking if error_message is empty) : if ($_GET[error_message]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global Variables Off
Hello, Paul [EMAIL PROTECTED] wrote: OK I guess I am closer = the variable is being passed as I tested but I guess is failing on the test: if (isset($_GET[error_message])) What do you mean by failing on the test? What are you trying to accomplish, btw? How are you testing it? Also, have you tried the single quotes here (in this portion) as mentioned by the others earlier? - E ...[snip]... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables that are arrays
Christopher J. Crane wrote: Can I do this? global $Ticker=array(); I don't know, what happens when you try it? HTH Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables that are arrays
I didn't do it yet. The script I am working on is large with many variables so I was hoping someone else would know before I do it. Chris Hewitt [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Christopher J. Crane wrote: Can I do this? global $Ticker=array(); I don't know, what happens when you try it? HTH Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Global variables
how can I use global variables in my web portal? I have read the php documentation, but it works only in the same file. I want use more global variable on many php site. For example: In login.php I use the code $first=mysql_result($result,0,FIRST_NAME); and I want to print this $first variable all of my php site. You can't. You can, however, have a config.php or type page that's include()'d on every page in your site where you define these variables. For things like this that you draw from the database, it would be a good idea to query once and add to the session. I find it useful to use something like a $_CONF[] array. $_CONF['user'] = 'user'; $_CONF['path'] = '/home/user/htdocs/'; etc... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global variables
On 2 Oct 2002 at 22:06, Anna Gyor wrote: how can I use global variables in my web portal? I have read the php documentation, but it works only in the same file. I want use more global variable on many php site. For example: In login.php I use the code $first=mysql_result($result,0,FIRST_NAME); and I want to print this $first variable all of my php site. Easy, use one script for your whole site. There is nothing that drives me more nuts than to encounter an application whose developers have left town and run into global variables. I don't mind file scoped variables so much, but to make a variable global across an application can drive one nuts when trying to debug. That said, I do use global variables but they are from a class whose 'object' is global. I don't have 3000 php files running all over my site as I've seen done. I have just a couple of *handlers* that use classes and I have one class which creates my global array which is shared. It's very easy to trace variables. I'd be very careful before I began to make variables global without some EASYmeans of tracing them. And it gets real interesting when one file inherits another which inherits another and in any one of them the value of your global variable can be changed. Does anyone know a good way for tracing such things? Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global variables
Hi, Thursday, October 3, 2002, 6:06:52 AM, you wrote: AG Hello, AG how can I use global variables in my web portal? I have read the php AG documentation, but it works only in the same file. AG I want use more global variable on many php site. AG For example: AG In login.php I use the code AG $first=mysql_result($result,0,FIRST_NAME); AG and I want to print this $first variable all of my php site. AG Thanks! If you are wanting it to be 'global' for the same visitor across your site use php session functions. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables inside of a function
On Friday, June 21, 2002, at 09:23 AM, Mark McCulligh wrote: Is there a way to access a session variables or server variables from inside a function? I have a function and was trying to use $PHP_SELF inside of it. I get a variable undefined error. Out side of the function it works fine. I don't want to parameter pass the global variables to the function, I know this would work, but I would have to many variables to pass. This is why superglobals were invented. Use $_SERVER['PHP_SELF'] Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables inside of a function
I tried using $_SERVER['PHP_SELF'] and $HTTP_SERVER_VARS['PHP_SELF'] but got the same error. I found the answer on www.php.net. function blah() { global $PHP_SELF; echo $PHP_SELF; } Thanks for your help, Mark. -- On Friday, June 21, 2002, at 09:23 AM, Mark McCulligh wrote: Is there a way to access a session variables or server variables from inside a function? I have a function and was trying to use $PHP_SELF inside of it. I get a variable undefined error. Out side of the function it works fine. I don't want to parameter pass the global variables to the function, I know this would work, but I would have to many variables to pass. This is why superglobals were invented. Use $_SERVER['PHP_SELF'] Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
Thanks Jason, Works great in htaccess Zac - Original Message - From: Jason Wong [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 06, 2002 4:08 AM Subject: Re: [PHP] global variables without sessions on apache On Thursday 06 June 2002 06:05, Zac Hillier wrote: Miguel, I mean that the variables will never change per Virtual host but that the site is a template for many sites and these vars are part of the distinction for each site / Virtual Host. So far the suggestions of using the auto-prepend in the php.ini have not seemed to cater for this. Can you help further? The auto-prepend thing can be set per-site if you put it in the apache.conf file, and possibly per-directory as well (haven't tried it) if put in .htaccess files. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* You will have a head crash on your private pack. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
On Wednesday 05 June 2002 20:40, Zac Hillier wrote: Hi, Is it possible using php on our own apache server to create global variables for virtual host without having to use session variables. We would like to have three variables that are constant for each virtual host and that are available from every page, I thought it would be possible with htaccess or http.conf but am struggling to find documentation for it. Use an auto-prepend file. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* QOTD: The baby was so ugly they had to hang a pork chop around its neck to get the dog to play with it. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
I'm not sure about at a htaccess level, but at a php.ini level I believe you can set a file to always include at the top of every php page. This file could simply be: ? $var1 = foo; $var2 = bah; ? Not sure on the specifics, but it was discussed on the list in the last two weeks, and i'm sure there is documentation for the php.ini file IN the the php.ini file, and on the website. Justin French on 05/06/02 10:40 PM, Zac Hillier ([EMAIL PROTECTED]) wrote: Hi, Is it possible using php on our own apache server to create global variables for virtual host without having to use session variables. We would like to have three variables that are constant for each virtual host and that are available from every page, I thought it would be possible with htaccess or http.conf but am struggling to find documentation for it. Thanks Zac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
Jason, Could you expand on this a little more? I've tried searching for auto-prepend in both php documentation and apache and cannot find anything thats relates to our needs. Thanks for your help Zac - Original Message - From: Jason Wong [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 05, 2002 2:46 PM Subject: Re: [PHP] global variables without sessions on apache On Wednesday 05 June 2002 20:40, Zac Hillier wrote: Hi, Is it possible using php on our own apache server to create global variables for virtual host without having to use session variables. We would like to have three variables that are constant for each virtual host and that are available from every page, I thought it would be possible with htaccess or http.conf but am struggling to find documentation for it. Use an auto-prepend file. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* QOTD: The baby was so ugly they had to hang a pork chop around its neck to get the dog to play with it. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
On Wednesday 05 June 2002 22:45, Zac Hillier wrote: Could you expand on this a little more? I've tried searching for auto-prepend in both php documentation and apache and cannot find anything thats relates to our needs. In php.ini there is a setting called auto_prepend_file. Set it to whatever file you want then in that file define your 'global variables'. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Banacek's Eighteenth Polish Proverb: The hippo has no sting, but the wise man would rather be sat upon by the bee. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
On Wed, 5 Jun 2002, Zac Hillier wrote: Is it possible using php on our own apache server to create global variables for virtual host without having to use session variables. We would like to have three variables that are constant for each virtual host and that are available from every page, I thought it would be possible with htaccess or http.conf but am struggling to find documentation for it. When you say that are constant do you mean that they never change or just that they are the same for each page at any given time? If you need dynamic variables shared between all your pages, you're going to have to either use a database or shared memory as documented at: http://www.php.net/manual/en/ref.sem.php miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
Miguel, I mean that the variables will never change per Virtual host but that the site is a template for many sites and these vars are part of the distinction for each site / Virtual Host. So far the suggestions of using the auto-prepend in the php.ini have not seemed to cater for this. Can you help further? -- ORIGINAL MESSAGE -- Is it possible using php on our own apache server to create global variables for virtual host without having to use session variables. We would like to have three variables that are constant for each virtual host and that are available from every page, I thought it would be possible with htaccess or http.conf but am struggling to find documentation for it. Thanks, Zac - Original Message - From: Miguel Cruz [EMAIL PROTECTED] To: Zac Hillier [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, June 05, 2002 7:12 PM Subject: Re: [PHP] global variables without sessions on apache On Wed, 5 Jun 2002, Zac Hillier wrote: Is it possible using php on our own apache server to create global variables for virtual host without having to use session variables. We would like to have three variables that are constant for each virtual host and that are available from every page, I thought it would be possible with htaccess or http.conf but am struggling to find documentation for it. When you say that are constant do you mean that they never change or just that they are the same for each page at any given time? If you need dynamic variables shared between all your pages, you're going to have to either use a database or shared memory as documented at: http://www.php.net/manual/en/ref.sem.php miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables without sessions on apache
On Thursday 06 June 2002 06:05, Zac Hillier wrote: Miguel, I mean that the variables will never change per Virtual host but that the site is a template for many sites and these vars are part of the distinction for each site / Virtual Host. So far the suggestions of using the auto-prepend in the php.ini have not seemed to cater for this. Can you help further? The auto-prepend thing can be set per-site if you put it in the apache.conf file, and possibly per-directory as well (haven't tried it) if put in .htaccess files. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* You will have a head crash on your private pack. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Global variables
Look at the auto-prepend or auto-append feature. -Original Message- From: serge gedeon [mailto:[EMAIL PROTECTED]] Sent: 29 May 2002 14:35 To: [EMAIL PROTECTED] Subject: [PHP] Global variables Dear sir, I would like to know if I could create using PHP, global variables that I could use in diferrent files. I don't want to use http_get_vars or post or cookies is there an other way? Thank you. Serge GEDEON _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Global variables
Sounds like a job for $_SESSION to me... http://www.php.net/manual/en/ref.session.php ---John Holmes... -Original Message- From: serge gedeon [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 29, 2002 9:36 AM To: [EMAIL PROTECTED] Subject: [PHP] Global variables Dear sir, I would like to know if I could create using PHP, global variables that I could use in diferrent files. I don't want to use http_get_vars or post or cookies is there an other way? Thank you. Serge GEDEON _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Global variables
use a database ed At 04:35 PM 5/29/2002 +0300, serge gedeon wrote: Dear sir, I would like to know if I could create using PHP, global variables that I could use in diferrent files. I don't want to use http_get_vars or post or cookies is there an other way? Thank you. Serge GEDEON _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables
Jule wrote: Hey, i'm just wondering if there is another way to write global variables to a global.php, now i just the whole fopen etc script, where i open a file and write the sctring $number_right = [whatever number it is] to the file, but is there a different way to write it to the file with one simple command? i could use cookies, but i prefer a simpler way. thanks Jule At want point did you stop and think that it would be *easier* to write information to a file? You could use cookies and should use cookies if your looking for a simpler way, sessions as well. If you don't mind information not being around the next time the user returns (after closing his/her browser) you could write to the always global always available $_SESSION array. For example $_SESSION['foo']=bar; and $_SESSION['bar']=foo; It's not writing to a file, but is one simple command and the information you store will follow them anywhere within your site. If you want save the information you could just as easily use $_COOKIES. But would require that you use the setcookie command. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] global variables
This is simpler than cookies?? Anyway, that's how you have to do it. Fopen(), fwrite(), fclose()...not any way simpler that I know of. ---John Holmes... -Original Message- From: Jule [mailto:[EMAIL PROTECTED]] Sent: Saturday, May 04, 2002 6:23 PM To: [EMAIL PROTECTED] Subject: [PHP] global variables Hey, i'm just wondering if there is another way to write global variables to a global.php, now i just the whole fopen etc script, where i open a file and write the sctring $number_right = [whatever number it is] to the file, but is there a different way to write it to the file with one simple command? i could use cookies, but i prefer a simpler way. thanks Jule -- Jule Slootbeek [EMAIL PROTECTED] http://blindtheory.cjb.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] global variables
global $genpasswd; ___ Justin Bain Rodino Technology Analyst/Systems Engineer p. 219.524.1000 f. 219.524.1001 e. [EMAIL PROTECTED] -Original Message- From: Peter [mailto:[EMAIL PROTECTED]] Sent: Monday, September 24, 2001 1:28 PM To: PHP List Subject: [PHP] global variables Hi, I am have a function in which I have created a variable in it called $genpassword. I find that I am unable to carry this variable over to the the other scripts to use because it is a local variable and its value exists only in the function. Is there anyway that I can take the value in $genpassword, a local variable and change it into a global variable so that other scripts will recognize it? Thanks. Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] global variables
$bar = 'abc'; function foo() { global $bar; $bar = 'def'; } foo(); echo $bar; // def http://www.php.net/manual/en/language.variables.scope.php regards, Philip Olson On Tue, 25 Sep 2001, Peter wrote: Hi, I am have a function in which I have created a variable in it called $genpassword. I find that I am unable to carry this variable over to the the other scripts to use because it is a local variable and its value exists only in the function. Is there anyway that I can take the value in $genpassword, a local variable and change it into a global variable so that other scripts will recognize it? Thanks. Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables - Local Scope
Well, you could try: extract( $GLOBALS ) inside a function - that might work.. At 22:14 26/07/2001 -0400, [EMAIL PROTECTED] wrote: How can I read in all of the global variables and give them local scope? PLEASE HELP ME. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] - Brian White Step Two Designs Pty Ltd - SGML, XML HTML Consultancy Phone: +612-93197901 Web: http://www.steptwo.com.au/ Email: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables -- why not have them?
You must learn it's way if you want to be effective. Also take a look at design features proposed for PHP5. Looks promising and more C++ like, so better compare it with the later one. I went to php.net and searched for some kind of docs on PHP5, but found not a word. Where can I see this feature list? -- Julio Nobrega. Yes, I am developing another 'Portal-System' Have a look: http://sourceforge.net/projects/toca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables -- why not have them?
Hi Inércia! On Sun, 08 Jul 2001, Inércia Sensorial wrote: You must learn it's way if you want to be effective. Also take a look at design features proposed for PHP5. Looks promising and more C++ like, so better compare it with the later one. I went to php.net and searched for some kind of docs on PHP5, but found not a word. Where can I see this feature list? erm, Zeev wrote to the list some time ago and gave a link somewhere inside www.zend.com site. As I don't have it handy I'll just point you to the site. [n.b. is on zend.com cause the features regard the Zend engine] -- teodor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables -- why not have them?
I dislike the GLOBAL statement in that many of the bugs that get me scratching my head are to do with when I have forgotten to use it. Then you're probably using it way too often. Global scope variable are inherently dangerous and cause more problems than they're worth. I've been in this business well nigh 30 years now and have had more problems with globals than I can shake a stick at. Passing parameters ain't a bad thing, you know, even when what you're passing is a variable declared in global scope (like variables set via post or get). Global is inelegant by definition ... I worked in Fortran 77 for 10 of those years; we were really careful with common blocks and included them only where absolutely necessary. Passing array blocks was in almost all cases a better thing and was not any slower. Mark C. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables -- why not have them?
At 20:13 8/07/2001 -0500, Mark Charette wrote: I dislike the GLOBAL statement in that many of the bugs that get me scratching my head are to do with when I have forgotten to use it. Then you're probably using it way too often. It is usually for SCRIPT_NAME, or one of the CGI parameters. The CGI parameters are arguable, but I pretty much consider SCRIPT_NAME to be a global constant. Brian - Brian White Step Two Designs Pty Ltd - SGML, XML HTML Consultancy Phone: +612-93197901 Web: http://www.steptwo.com.au/ Email: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables -- why not have them?
on 7/8/01 7:57 PM, Brian White at [EMAIL PROTECTED] wrote: I dislike the GLOBAL statement in that many of the bugs that get me scratching my head are to do with when I have forgotten to use it. Then you're probably using it way too often. It is usually for SCRIPT_NAME, or one of the CGI parameters. The CGI parameters are arguable, but I pretty much consider SCRIPT_NAME to be a global constant. php does have constants which are _always_ global. define (SCRIPT_NAME, $passed_in_script); then you refer to it like my_function() { printf(script is %s,SCRIPT_NAME); } notice there are no quotes or '$' or anything. i've recently changed $DEBUG to DEBUG for things like define(DEBUG, 1); my_db_function() { $rid = $db-query($query); if (!DB::isError) { do_something_cool(); } else { if (DEBUG) printf(!-- bummer, query failed : %s --\n,$rid-getMessage()) } -- mike cullerton -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables -- why not have them?
At 02:55 PM 7/7/01 -0400, Mitch Vincent wrote: I've been using PHP for several years now and one question has plagued me the entire time. Why doesn't PHP have global variables? Before someone says it, I do know PHP sort of does have global variables, but having to specify GLOBAL in any function I want to see that variable in disqualifies it from being a truly global variable IMHO.. I suppose I'm more curious than anything else.. Thanks! -Mitch I don't know what the makers of PHP had in mind, but from my experience, having truly global variables is a very bad idea. In fact, you should be trying to limit your need of global variables, so that your program can count on the integrity of the variables. John Meyer [EMAIL PROTECTED] Programmer If we didn't have Microsoft, we'd have to blame ourselves for all of our programs crashing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables? (unset/set or what?)
Try the define function. That will define a constant that you will always have access to (within functions, through various included files,etc.) Or you can write values to the $GLOBALS array of global variables. $GLOBALS[userPassword]=u8943fd; Will define a variable that is accessible as $userPassword. outside of functions and within functions available after the global $userPassword; command is within the function. HTH, Michael Richard wrote: Greetings. I have about two include files which are included in every php page that I have, and I wish to store global variables, such as passwords, usernames and other details information. After going through the PHP manual, all I could find was UNSET/SET global variables, but I don't know if that is the one to use or not... they looked like if they were to be doing something else. Any help or ideas? - Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables? (unset/set or what?)
So i should start the header (or wherever in the header) with : $GLOBALS[userPassword] = whatever; function cp() { global $userPassword; // $userPassword is 'whatever' // } Did I get it or am I just too tired? - Richard Michael Stearne [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Try the define function. That will define a constant that you will always have access to (within functions, through various included files,etc.) Or you can write values to the $GLOBALS array of global variables. $GLOBALS[userPassword]=u8943fd; Will define a variable that is accessible as $userPassword. outside of functions and within functions available after the global $userPassword; command is within the function. HTH, Michael Richard wrote: Greetings. I have about two include files which are included in every php page that I have, and I wish to store global variables, such as passwords, usernames and other details information. After going through the PHP manual, all I could find was UNSET/SET global variables, but I don't know if that is the one to use or not... they looked like if they were to be doing something else. Any help or ideas? - Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables? (unset/set or what?)
In article 9e6s21$2rk$[EMAIL PROTECTED], [EMAIL PROTECTED] (Richard) wrote: So i should start the header (or wherever in the header) with : $GLOBALS[userPassword] = whatever; function cp() { global $userPassword; // $userPassword is 'whatever' // } You're making an extra step. The variables stored in the $GLOBALS array don't have to be declared as global within a function. They're already available within the function. To make a global variable available within a function's local namespace, you _either_: * pass it by reference: function cp($userPassword) * declare it as a global: global $userPassword * make it an element of the $GLOBALS array: $GLOBALS['userPassword'] (You could also pass by value, but then you're dealing with a copy of the variable instead of the variable itself.) -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables? (unset/set or what?)
So this will do then: $GLOBALS[userPassword] = whatever; And when I need to use it, I use echo userPassword; and such alike? What if I would like to change it? Can I simply use 'userPassword=whatever'; ? Thanks, Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables
Aaron Tuller schrieb: At 1:16 AM + 4/19/01, Philip Olson wrote: pre ?php var_dump($GLOBALS) ? /pre don't do that, at least I think it will recursively traverse the $GLOBALS arrary (since $GLOBALS itself is $GLOBAL) and you will never end. print_r() does have that bug, not var_dump(). http://www.php.net/manual/en/function.print-r.php Ulf -- Neu: PEAR Menu 3 - Navigationsstrukturen dynamisch dargestellt http://www.ulf-wendel.de/projekte/menu/tutorial.php | http://www.phpdoc.de -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Global variables
I know there is a way to do it in Perl, but is there anyway in PHP to display all of the global variables. Such as OS, browser, date/time, that sort of thing I know I could print each one seperately, but are they all stored in an array somewhere? ? phpInfo(); ? That should show you everything... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables
Have a look at the enormous $GLOBALS array, something like : pre ?php var_dump($GLOBALS) ? /pre As previously mentioned, phpinfo() provides some pretty information and it may be more what you want. Regarding $GLOBALS, (as quoted from the manual) : "The $GLOBALS array is an associative array with the name of the global variable being the key and the contents of that variable being the value of the array element." Also, be sure to look around here : http://www.php.net/manual/en/language.variables.predefined.php regards, philip On Wed, 18 Apr 2001, JCampbell wrote: I know there is a way to do it in Perl, but is there anyway in PHP to display all of the global variables. Such as OS, browser, date/time, that sort of thing I know I could print each one seperately, but are they all stored in an array somewhere? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables
At 1:16 AM + 4/19/01, Philip Olson wrote: pre ?php var_dump($GLOBALS) ? /pre don't do that, at least I think it will recursively traverse the $GLOBALS arrary (since $GLOBALS itself is $GLOBAL) and you will never end. -aaron -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global variables
At 1:16 AM + 4/19/01, Philip Olson wrote: pre ?php var_dump($GLOBALS) ? /pre don't do that, at least I think it will recursively traverse the $GLOBALS arrary (since $GLOBALS itself is $GLOBAL) and you will never end. This is true with print_r($GLOBALS) up until 4.0.4 where it was fixed, which is why I used var_dump in the example although print_r is much prettier :-) regards, Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Global Variables
Jon wrote: Hi, I need to retrieve some information from a database, asociated with the user session so I could query this information whenever I want through the user session. I am searching for something similar to ASPs global variables if there is anything equivalent with PHP. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] Aren't you looking for session-handling? Look at: http://www.php.net/manual/en/ref.session.php or (Spain): http://www.php.net/manual/es/ref.session.php -- * RzE: *** ** Renze Munnik ** ** E: [EMAIL PROTECTED] ** M: +31 6 218 111 43 *** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]