ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-general
php-general
Re: [PHP] using new AUTOGLOBALS
by Philip Olson other posts by this author
Apr 5 2002 8:00PM messages near this date
Re: [PHP] using new AUTOGLOBALS | [PHP] Re: using new AUTOGLOBALS
As miguel suggests, these are just arrays.  Use them like 
any other array:

  print $arr['key'];
  print "string {$arr['key']} string";
  print 'string ' . $arr['key'] . ' string';
  etc.

Read about arrays and strings:
  http://us2.php.net/manual/en/language.types.array.php
  http://de.php.net/manual/en/language.types.string.php
  http://www.zend.com/zend/tut/using-strings.php

With the only difference being that they are *super* 
global, so no need for: global $_SERVER;  in your 
functions, etc.

Now if you want to be truly cutting edge :) Then consider 
extract() or import_request_variables() like so:

  import_request_variables('g', 'g_');

Which will allow:
  // http://www.example.com/test.php?foo=bar
  print $g_foo;  // the GET variable foo

Which is like:
  print $_GET['foo'];
  print $HTTP_GET_VARS['foo'];

See manual entry for more details and features:
  http://uk.php.net/import_request_variables

The above assumes you want it to be from GET and only GET, 
maybe this is not your desire so modify accordingly.

Or let's say you want to use server predefined variables such 
as $PHP_SELF, $DOCUMENT_ROOT, etc. yet have register_globals 
remain off.  Since register_globals = on creates these, 
consider:

  a) Using $_SERVER or $HTTP_SERVER_VARS in your code i.e.
       print $_SERVER['HTTP_USER_AGENT'];
  b) Or use extract()

For example:

  // If register_globals are off (0) then extract
  if (!ini_get('register_globals')) {
    extract($HTTP_SERVER_VARS);
  }

  // We just created these!
  print $PHP_SELF;
  print $REQUEST_URI;

Going through $_SERVER is good in that you're not wasting 
energy creating variables you'll never use, so do as 
you will.

extract() has many many options, read about them:
  http://ca.php.net/extract

All of the above should give ideas, have fun!

Regards,
Philip Olson

p.s. Use a mirror
  http://uk.php.net/mirrors.php



On Fri, 5 Apr 2002, Miguel Cruz wrote:

>  On Fri, 5 Apr 2002, cyberskydive wrote:
>  > So I wanna learn how to code properly with register_globals off, I reead on
>  > PHP.net about the new auto globals and inmy new php4.1.2 windows
>  > installation using php.ini-rec edited according to the intall.txt file, and
>  > a few changes from books I have (upload tmp dir etc) I'm off to learn how to
>  > use the new auto globals. I've tried $_REGISTER and $_POST .  Here is what I
>  > tried as a simple test.
>  > 
>  > <form method="post" action="somefile.php">
>  > <input type="text" name="is_name">
>  > <input type="submit">
>  > </form>
>  > 
>  > --somefile.php--
>  > 
>  > <?
>  > 
>  > print("$_REGISTER["is_name"]");
>  > or
>  > print("$_POST["is_name"]");
>  > 
>  > ?>
>  
>  Two problems.
>  
>  1) It's $_REQUEST, not $_REGISTER
>  
>  2) Take the outermost quotes off the argument to your print, like so:
>  
>     print $_REQUEST["is_name"];
>  
>  miguel
>  
>  
>  -- 
>  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
Thread:
cyberskydive
Miguel Cruz
Philip Olson
cyberskydive
Erik Price
Erik Price

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved