PHP - Superglobal / Register_globals
Hello All!
Can anyone explain why when I run the following code <?php print_r($GLOBALS); ?> I get the following output Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) ) which is expected since register_globals is set to off and no variables are defined, but when I add the following code. which is just to echo out a variable from the superglobal $_SERVER, the print_r($GLOBALS) now outputs all the superglobal $_SERVER variables as if echo somehow made all the variables available to the script and now $GLOBALS sees them. maybe a stupid question I don't know. For obvious reasons I can't show the output, but it's easy enough to run the code to view your systems output. <?php print_r($GLOBALS); echo "<br />"; echo "<br />"; echo $_SERVER["DOCUMENT_ROOT"]; ?> Thanks, steadythecourse Similar TutorialsHi, gday, how can I use the ucfirst variable on the posted variable after to form has been submitted to welcome my member? "<p>Welcome: ucfirst{$_SESSION['first_name']};" This is not working. Should I use it in the form instead? When I turn register_global is turned off (register_argc_argv is also set to off), this script won't work. How can I have register_globals turned off and make this work for me. Any help is highly appreciated. <?php $bd_me = mysql_bd_meect("localhost","db_me","pw_me"); mysql_select_db("db_me"); $query =sprintf("SELECT * FROM db WHERE unamename = '%s' AND stus = 'Banned'", mysql_real_escape_string($uname)); $query_new = mysql_query($query); if(mysql_num_rows($query_new)) { $login = "Sorry."; echo($login); } else { $result=sprintf("SELECT * FROM db WHERE unamename = '%s' AND password ='%s'", mysql_real_escape_string($uname), mysql_real_escape_string($password)); $resultf = mysql_query($result); if(mysql_num_rows ($resultf) == 0) { $login = "Failed."; echo($login); } else { $row = mysql_fetch_array($result); $uname=$row['uname']; $password=$row['password']; $login = "$uname=" . $uname . "$password=" . $password . "Successful."; echo($login); } } ?> Is there any other settings that needs to be changed in the php.ini to make this code work while register_globals is turned off? I have script that I need register_globals = On right now I have to put php.ini into root of my webpage on webhost. but that means it turn on register_globals = On for whole site. I have tried just putting php.ini into subdomain but does not work, well script does not work. I have tried to put AddHandler application/x-httpd-php5s .php into the .htaccess in subdomain but that does not work either, script stop working. I can not get script to work if php.ini is in root of webpage webhost. What I'm I doing wrong, thanks Hi all, Just moving my old website to a new server and I can't turn register_globals off. The company that designed the site for me has long gone and I don't know enough about php to do this...any help would be greatly appreciated. The error I am getting when trying to access the page is [01-Feb-2011 05:37:13] PHP Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 [01-Feb-2011 05:37:14] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'newquayu_uncover'@'localhost' (using password: YES) in /home/xmasphot/public_html/www.newquayuncovered.com/music/classes/DB_class.php on line 44 I have had to change the name of the database and the access details, this has been reflected in other documents but I am guessing that this is trying to use the orignal details somehow??? <? /* Script * Date Created: 07 Jun, 2004 * Last Updated: 07 Jun, 2004 * * DB_class.php */ class DB { //connection parameters var $host = ''; var $user = ''; var $password = ''; var $database = ''; //Database connection handle var $conn = NULL; //Query result var $result = false; var $row; function DB($host,$user,$password,$database,$persistent = true) { $this->host = $host; $this->user = $user; $this->password = $password; $this->database = $database; $this->perstitent = $perstitent; } function open() { //chose appropriate connect function if($this->perstitent) { $func = 'mysql_pconnect'; } else { $func = 'mysql_connect'; } //connect to mysql server $this->conn = $func($this->host,$this->user,$this->password); if(!$this->conn) { echo mysql_error(); exit; } //select the requested database if(!mysql_select_db($this->database,$this->conn)) { echo mysql_error(); exit; } return true; } function close() { return(mysql_close($this->conn)); } function error() { return(mysql_error()); } function query($sql) { /*if(!$this->result = mysql_query($sql,$this->conn)){ echo mysql_error(); exit; }*/ $this->result = mysql_query($sql,$this->conn); return $this->result; } function fetchobject($result='') { if(!$result){ $result = $this->result; } if(!$res = mysql_fetch_object($result,MYSQL_ASSOC)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function fetcharray() { if(!$res = mysql_fetch_array($this->result,MYSQL_NUM)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function fetchfield() { if(!$res = mysql_fetch_field($this->result)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function numrows($result='') { if(!$result){ $result = $this->result; } if(!$res = mysql_num_rows($result)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function affectedrows() { if(!$res = mysql_affected_rows($this->conn)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function insertid() { if(!$res = mysql_insert_id($this->conn)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function freeresult() { if(!$res = mysql_free_result($this->result)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } function fetchrow($result='') { if(!$result){ $result = $this->result; } if(!$res = mysql_fetch_row($result)){ if(mysql_error() != ""){ echo mysql_error(); exit; } } return $res; } } ?> Why won't this code work when register_globals is turned off (works fine when register_globals is on though). <?php $link = mysql_connect("localhost","un","pw"); mysql_select_db("the_db"); $username = $_POST['usernamex']; $surname = $_POST['surname']; $email = $_POST['email']; $result =sprintf("SELECT * FROM tbl WHERE username ='%s' || email = '%s'", mysql_real_escape_string($username), mysql_real_escape_string($email)); $resultfin = mysql_query($result); if (mysql_num_rows ($resultfin) > 0){ $register = "Retry."; echo($register); } else { $go =sprintf("INSERT INTO tbl (username, email, surname) VALUES ('%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($email), mysql_real_escape_string($surname)); $resultg = mysql_query($go); $register = "Successful."; echo($register); } ?> Thanks, Bickey. i have two SMTP scripts (attached) they need register_globals to be on to work without destroying one of my cookies. how do i modify them so that they dont need register_globals? thank you, sorry for the open ended question, ask me anything to help you help me! thanks. [attachment deleted by admin] In the following code, Code: [Select] // Register Globals if (ini_get('register_globals')) { ini_set('session.use_cookies', 'On'); ini_set('session.use_trans_sid', 'Off'); session_set_cookie_params(0, '/'); session_start(); $globals = array($_REQUEST, $_SESSION, $_SERVER, $_FILES); foreach ($globals as $global) { foreach(array_keys($global) as $key) { unset($$key); } } } the above destroys all globals if register_globals is on, as I understand it. However, if it does destroy all globals, can a web form continue to work? How do you allow form fields and other stuff to be used in a script even if you kill all the globals up front? Many thanks hi guys. i am trying to set a variable to the session global variable. I've initialized the session with session_start(); at the very beginning of my website, and then i try finding if a session variable has been set like so if(isset($_SESSION['user'])) { print 'user is logged in'; } but this works in reverse. i have not set any session variables, but asking if it is set, results in an affirmative answer. so i am thinking this is because of register_globals. because i went to read about register_globals, and it says that if register_globals is turned off, i cannot use any other varibale except members of the session array. i dont know what that is yet, but a question befo in the php manual it says register_globals is deprecated, and it appears i need to enable it to set other variables as session variables besides it's associative array. if this is true, how to enable register_globals and allow other variables to be used as session variables? |