Jump to content


Photo

register global questions


  • Please log in to reply
2 replies to this topic

#1 boxcar182

boxcar182
  • Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 July 2006 - 02:25 PM

i've just been looking through my php.ini file and i just read the part that goes.

; You should do your best to write your scripts so that they do not require
; register_globals to be on;  Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = Off



but doesn't register globals have to be on to include pages like /?id=page here.

is there a way to get links working like that with register globals on then?

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 02:54 PM

no, you do not need register global on to enable any particular feature.

assume you have this kind of passing:

index.php?id=page&username=myname
and you want to print the username out.

with register global on, simply
echo $username;

without register global on,
echo $_GET['username'];

relying on register global is generally not good style.  There're many reason for it.

Bottom line is, accessing your GET and POST data via $_GET and $_POST


Life's too short for arguing.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 July 2006 - 04:18 PM

When register_globals is off you have to use a set of predifined variables called superglobals. The following are the superglobas:
$_POST, $_GET, $_SESSION, $_COOKIe, $_SERVER

Basically to get session data you use $_SESSION, for cookies you use $_COOKIE, for server variables you use $_SERVER, for get/post'd data you you use $_GET or $_POST




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users